Skip to content

Instantly share code, notes, and snippets.

@delvedor
Created January 5, 2022 10:19
Show Gist options
  • Save delvedor/709f4d71527be93b7450a4ced87aba16 to your computer and use it in GitHub Desktop.
Save delvedor/709f4d71527be93b7450a4ced87aba16 to your computer and use it in GitHub Desktop.
import Fastify from 'fastify'
const fastify = Fastify()
fastify.register(async fastify => {
fastify.setErrorHandler(async err => {
console.log(err.message) // 'kaboom'
throw new Error('caught')
})
fastify.get('/encapsulated', async () => {
throw new Error('kaboom')
})
})
fastify.setErrorHandler(async err => {
console.log(err.message) // 'caught'
throw new Error('wrapped')
})
const res = await fastify.inject('/encapsulated')
console.log(res.json().message) // 'wrapped'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment