-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Description
I'm using React Router as a...
framework
Reproduction
Summary: It's not clear how to centrally log errors from server-side resource routes that return JSON errors.
The doc for resource routes encourages you to return JSON from a REST/resource endpoint returning a Response.json, e.g. { status: 500 }.
Meanwhile, the doc on error reporting encourage you to report and log server-side errors by defining handleError in entry.server.tsx, explaining
This function is called whenever React Router catches an error in your application on the server.
handleError is indeed called if have an uncaught throw in a resource route, but if you politely return a 4xx or 5xx error Response from a React Router server API, there doesn't seem to be a documented way to centrally report and log this.
If you follow Sentry's guide for integrating with React Router 7, you'll find that Sentry will log uncaught exceptions, but not Responses with error status codes.
I'm not sure if this is
- A problem outside React Router's purview, in which case the Error Reporting doc should probably mention this
- A problem React Router does have a solution for, which should be noted in the Error Reporting doc, or
- This is a bug (a central error handler like
handleErrorshould be called if you return a 4XX or 5XX via Response.json from an API)
I have a sample project that demonstrates this dynamic.
System Info
System:
OS: macOS 15.2
CPU: (10) arm64 Apple M1 Max
Memory: 806.50 MB / 32.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.18.1 - ~/.local/state/fnm_multishells/57540_1737396662913/bin/node
npm: 10.8.2 - ~/.local/state/fnm_multishells/57540_1737396662913/bin/npm
Browsers:'
Arc: 1.78.1 (132.0.6834.84)
Chrome Canary: 134.0.6983.0
Safari: 18.2
npmPackages:
@react-router/dev: ^7.1.3 => 7.1.3
@react-router/express: * => 7.1.3
@react-router/node: ^7.1.3 => 7.1.3
@react-router/serve: ^7.1.3 => 7.1.3
react-router: ^7.1.3 => 7.1.3
vite: ^5.4.11 => 5.4.12Used Package Manager
npm
Expected Behavior
Either:
- The doc on error reporting mentions how to log/report HTTP error
Responses returned from resource routes, or - handleError triggers when you return a HTTP error
Response
Actual Behavior
There isn't a clearly documented way to log/report these errors centrally.