Skip to content

Errors returned from resources are not covered by error reporting #12875

@apike

Description

@apike

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

  1. A problem outside React Router's purview, in which case the Error Reporting doc should probably mention this
  2. A problem React Router does have a solution for, which should be noted in the Error Reporting doc, or
  3. This is a bug (a central error handler like handleError should 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.12

Used Package Manager

npm

Expected Behavior

Either:

  1. The doc on error reporting mentions how to log/report HTTP error Responses returned from resource routes, or
  2. handleError triggers when you return a HTTP error Response

Actual Behavior

There isn't a clearly documented way to log/report these errors centrally.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions