fastify.setErrorHandler is not working.
That's my first version. I'm new guy here.
Steps to reproduce the behavior:
fastify.setErrorHandler((error, request, reply) => {
reply.send(`Internal Server Error - ${error}`);
})
fastify.get('/err', async (req,reply) =>{
return new Error('my error!')
})
didn't catch the Error
{
"statusCode":500,
"error":"Internal Server Error",
"message":"Something went wrong"
}
I think you have fastify-sensible installed, if so, you should register it like this
fastify.register(require('fastify-sensible'), { errorHandler: false } )
Because it is hiding your error handler.
Moreover, you should throw error throw new Error('my error!') in async functions
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Most helpful comment
I think you have fastify-sensible installed, if so, you should register it like this
Because it is hiding your error handler.
Moreover, you should throw error
throw new Error('my error!')in async functions