handleError
inconsistently returns wrapped & unwrapped ErrorResponse
objects, making it hard to filter errors from telemetry services
#7208
Labels
What version of Remix are you using?
v1.19.3
Are all your remix dependencies & dev-dependencies using the same version?
Diagnosis
I started running into this because I upgraded my Sentry integration to use the v2 future flags according to their guide, and found I was still getting a handle of 4xx errors reported to Sentry despite filtering them out like so:
Specifically, I was getting
You made a POST request to "/" but did not provide an
actionfor route "routes/_index", so there is no way to handle the request.
, normally a 405ErrorResponse
, thrown as anError
object whenever an automated crawler tried to POST to my website. However, 404s would be thrown as ordinaryErrorResponse
objects so I could filter them using the above code.I isolated the issue to:
remix/packages/remix-server-runtime/server.ts
Lines 186 to 188 in 8779b24
Here, whenever the server runtime detects an
ErrorResponse
, it tries to unwrap the original error and send it to the user, if it exists. This is understandable behaviour because sometimes the user might want to manually attach an error to their response, especially if it’s a plain old 500 without any other useful information.However:
https://github.com/remix-run/react-router/blob/496b1fe8253643171ecca6e6a945d98386c4eb00/packages/router/router.ts#L4142-L4147
react-router
creates a good number ofErrorResponse
s by passing a dummynew Error(errorMessage)
to the object, which then gets unwrapped. This gives me less information when looking athandleError
, and I can’t easily filter out 4xx status codes. Instead, I have to manually compare the error message with hard-coded strings, which is really brittle. (I assume the reason I don’t see this for 404s if because it creates thoseErrorResponse
s in a different way).Proposed Solutions
Before I write up a PR, I want to clarify with the Remix team what the best solution would be:
error.error
, and instead re-exportisRouteErrorResponse
from@remix-run/server-runtime
and downstream dependencies. This would allow the user to perform similar checks inhandleError
that they might do on the frontend.ErrorResponse
in thereact-router
code.(More broadly, the story for error telemetry in v2 is painful. Those Sentry docs illustrate the problem—we don’t clearly demarcate between ‘client-side’ and ‘server-side’ errors in the
ErrorBoundary
(noting that even those terms can be misnomers in the context of RR), so the user has to add their own filters to prevent duplication.)The text was updated successfully, but these errors were encountered: