You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fastify integration captures 4xx errors raised before the reply status is set (e.g. empty JSON body) #24926
No tracesSampleRate, no setupFastifyErrorHandler, no custom shouldHandleError.
Steps to Reproduce
Run a NestJS app on FastifyAdapter (or a plain Fastify 5 app) with the SDK set up as above.
Send a request with a JSON content type and an empty body: curl -X POST http://localhost:3000/ -H 'Content-Type: application/json'
Expected Result
The client gets a 400 and nothing is sent to Sentry, since the default shouldHandleError skips 4xx.
Actual Result
The client gets a 400, but Sentry receives an unhandled error:
FastifyError: Body cannot be empty when content-type is set to 'application/json'
mechanism: auto.function.fastify, handled: false
The same happens for an invalid JSON body (FST_ERR_CTP_INVALID_JSON_BODY).
Additional Context
Fastify runs onError hooks before it applies the error's status to the reply. For errors raised outside the route handler, such as body parsing, defaultShouldHandleError still reads reply.statusCode === 200, which it treats as "capture". #18418 fixed the same symptom upstream in Fastify 5.7.0, but only for route handler errors on the diagnostics channel path.
This started for us with v11, where fastifyIntegration registers the onError hook automatically (#23460). Before that, the hook was only added by setupFastifyErrorHandler, which NestJS apps don't call.
A fix is up in #24924: when reply.statusCode is still the default 200, the default shouldHandleError resolves the status the same way Fastify's setErrorStatusCode does.
Priority
React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it.
Activity
linear-code commentedon Oct 1, 2026
JS-3860
nicohrubec commentedon Oct 2, 2026
Hey, thanks for writing in. I'll take a look.
fix(server-utils): Skip Fastify 4xx errors raised before the reply st…
nicohrubec commentedon Oct 2, 2026
Just merged the fix, will go out with the next release today.
github-actions commentedon Oct 2, 2026
A PR closing this issue has just been released 🚀
This issue was referenced by PR #24924, which was included in the 11.3.0 release.