Repository navigation
Description
Is there an existing issue for this?
- I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
- I have reviewed the documentation https://docs.sentry.io/
- I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using?
@sentry/nestjs
SDK Version
11.1.0
Framework Version
NestJS 12, @nestjs/platform-fastify 12, Fastify 5.12.5
Link to Sentry event
Reproduction Example/SDK Setup
Sentry.init({
integrations: defaults => [
...defaults.filter(integration => integration.name !== 'ProcessSession'),
Sentry.httpIntegration({ sessions: false }),
],
});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.
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsNo status
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.