Prerequisites
Fastify version
4.11.0
Plugin version
No response
Node.js version
18.5.0
Operating system
Windows
Operating system version (i.e. 20.04, 11.3, 10)
10
Description
setErrorHandler(err,req,reply) returns 200 as reply.statusCode instead of 500.
I'd expect that if an API breaks due to unexpected error, the error handler reply status code should be 500.
This feature has changed from fastify 3 to fastify 4 (just tested it) because on Fastify 3 it correctly returns 500.
Steps to Reproduce
import fastify from 'fastify';
const app = fastify();
app.setErrorHandler((error, request, response) => {
console.log(error, error.statusCode, response.statusCode);
response.status(response.statusCode).send({ error: error.message })
})
app.get('/', (request, reply) => {
const m = structuredClone(request);
})
await app.listen({ host: '0.0.0.0', port: 8080 })
Expected Behavior
Expected behavior is to have reply.statusCode equal to 500 instead of 200
Prerequisites
Fastify version
4.11.0
Plugin version
No response
Node.js version
18.5.0
Operating system
Windows
Operating system version (i.e. 20.04, 11.3, 10)
10
Description
setErrorHandler(err,req,reply)returns 200 asreply.statusCodeinstead of 500.I'd expect that if an API breaks due to unexpected error, the error handler reply status code should be 500.
This feature has changed from fastify 3 to fastify 4 (just tested it) because on Fastify 3 it correctly returns 500.
Steps to Reproduce
Expected Behavior
Expected behavior is to have
reply.statusCodeequal to 500 instead of 200