Auto-commit 2026-04-29 16:31

This commit is contained in:
2026-04-29 16:31:27 -04:00
parent e8687bb6b2
commit 0495ee5bd2
19691 changed files with 3272886 additions and 138 deletions

View File

@@ -0,0 +1,50 @@
'use strict'
const { test } = require('tap')
const Fastify = require('..')
test('encapsulates an error handler', async t => {
t.plan(3)
const fastify = Fastify()
fastify.register(async function (fastify) {
fastify.setErrorHandler(async function a (err) {
t.equal(err.message, 'kaboom')
throw new Error('caught')
})
fastify.get('/encapsulated', async () => { throw new Error('kaboom') })
})
fastify.setErrorHandler(async function b (err) {
t.equal(err.message, 'caught')
throw new Error('wrapped')
})
const res = await fastify.inject('/encapsulated')
t.equal(res.json().message, 'wrapped')
})
test('onError hook nested', async t => {
t.plan(4)
const fastify = Fastify()
fastify.register(async function (fastify) {
fastify.setErrorHandler(async function a (err) {
t.equal(err.message, 'kaboom')
throw new Error('caught')
})
fastify.get('/encapsulated', async () => { throw new Error('kaboom') })
})
fastify.setErrorHandler(async function b (err) {
t.equal(err.message, 'caught')
throw new Error('wrapped')
})
fastify.addHook('onError', async function (request, reply, err) {
t.equal(err.message, 'kaboom')
})
const res = await fastify.inject('/encapsulated')
t.equal(res.json().message, 'wrapped')
})