Title: Fastify integration captures 4xx errors raised before the reply status is set (e.g. empty JSON body) · Issue #24926 · getsentry/sentry-javascript · GitHub
Open Graph Title: Fastify integration captures 4xx errors raised before the reply status is set (e.g. empty JSON body) · Issue #24926 · getsentry/sentry-javascript
X Title: Fastify integration captures 4xx errors raised before the reply status is set (e.g. empty JSON body) · Issue #24926 · getsentry/sentry-javascript
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/...
Open Graph 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 th...
X 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 th...
Opengraph URL: https://github.com/getsentry/sentry-javascript/issues/24926
X: @github
Domain: github.com
IPv4 address: 140.82.113.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Fastify integration captures 4xx errors raised before the reply status is set (e.g. empty JSON body)","articleBody":"### Is there an existing issue for this?\n\n- [x] I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues\n- [x] I have reviewed the documentation https://docs.sentry.io/\n- [x] I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases\n\n### How do you use Sentry?\n\nSentry Saas (sentry.io)\n\n### Which SDK are you using?\n\n@sentry/nestjs\n\n### SDK Version\n\n11.1.0\n\n### Framework Version\n\nNestJS 12, `@nestjs/platform-fastify` 12, Fastify 5.12.5\n\n### Link to Sentry event\n\nhttps://kpler.sentry.io/issues/7763870286/events/77524398057d4e309eeb9a3f443f4af0/?project=4511819824889856\n\n### Reproduction Example/SDK Setup\n\n```js\nSentry.init({\n integrations: defaults => [\n ...defaults.filter(integration => integration.name !== 'ProcessSession'),\n Sentry.httpIntegration({ sessions: false }),\n ],\n});\n```\n\nNo `tracesSampleRate`, no `setupFastifyErrorHandler`, no custom `shouldHandleError`.\n\n### Steps to Reproduce\n\n1. Run a NestJS app on `FastifyAdapter` (or a plain Fastify 5 app) with the SDK set up as above.\n2. Send a request with a JSON content type and an empty body: `curl -X POST http://localhost:3000/ -H 'Content-Type: application/json'`\n\n### Expected Result\n\nThe client gets a 400 and nothing is sent to Sentry, since the default `shouldHandleError` skips 4xx.\n\n### Actual Result\n\nThe client gets a 400, but Sentry receives an unhandled error:\n\n```\nFastifyError: Body cannot be empty when content-type is set to 'application/json'\nmechanism: auto.function.fastify, handled: false\n```\n\nThe same happens for an invalid JSON body (`FST_ERR_CTP_INVALID_JSON_BODY`).\n\n### Additional Context\n\nFastify 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.\n\nThis 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.\n\nA 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.\n\n### Priority\n\n\u003csub>React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding `+1` or `me too`, to help us triage it.\u003c/sub>\n","author":{"url":"https://github.com/tobias-schnabel","@type":"Person","name":"tobias-schnabel"},"datePublished":"2026-10-01T09:36:11Z","url":"https://github.com/getsentry/sentry-javascript/issues/24926"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:4bdd0a7d-d501-52ef-a5e4-eb7b0c8b75fa |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D6BA:30AFC6:30F7:3D1C:6B0426A9 |
| html-safe-nonce | 832a1793151bd6a2502849012cdcc5c129b1603646676e9a2a2e6fd45a7ae261 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENkJBOjMwQUZDNjozMEY3OjNEMUM6NkIwNDI2QTkiLCJ2aXNpdG9yX2lkIjoiNDgzODgyMTQ0MDA3MTY3MzUxMyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | d520d1d1b4a495781b984da382d97fb377bb4fa753b17c6dd41de6796efa8972 |
| hovercard-subject-tag | issue:5660096584 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/getsentry/sentry-javascript/24926/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ba5be200a39b844e4ceb7518d1aafbc9b1c332b0e219cc60650b1df426a98ff1/getsentry/sentry-javascript/issues/24926 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ba5be200a39b844e4ceb7518d1aafbc9b1c332b0e219cc60650b1df426a98ff1/getsentry/sentry-javascript/issues/24926 |
| og:image:alt | 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 th... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | tobias-schnabel |
| hostname | github.com |
| expected-hostname | github.com |
| None | f8d9f404447ab5df341c8a92cf5fc927730ad1321e64ac57656444d2438097f1 |
| turbo-cache-control | no-preview |
| go-import | github.com/getsentry/sentry-javascript git https://github.com/getsentry/sentry-javascript.git |
| octolytics-dimension-user_id | 1396951 |
| octolytics-dimension-user_login | getsentry |
| octolytics-dimension-repository_id | 3328572 |
| octolytics-dimension-repository_nwo | getsentry/sentry-javascript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 3328572 |
| octolytics-dimension-repository_network_root_nwo | getsentry/sentry-javascript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | f7edccce04851591ee529948701779ce6819bc53 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width