defaultShouldHandleError
filters out common library errors with no documentation
#14970
Closed
3 tasks done
Labels
Package: node
Issues related to the Sentry Node SDK
Is there an existing issue for this?
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using?
@sentry/node
SDK Version
8.47.0
Framework Version
Express 5.0.1
Link to Sentry event
No response
Reproduction Example/SDK Setup
Steps to Reproduce
When calling the
/test
endpoint with a domain for which domain delegation permissions have been granted but with a user who doesn't have access to the admin directory endpoint, the upstream error thrown bygoogleapis
(atdirectory.users.get()
call) is a object containing.status < 500
value.Error JSON
When this error enters the Sentry middleware if no
shouldHandleError
was provided in thesetupExpressErrorHandler
call, thedefaultShouldHandleError
gets invokedsentry-javascript/packages/node/src/integrations/tracing/express.ts
Lines 115 to 133 in 1048a43
Now this checks whether the exception has any of
status
,statusCode
,status_code
oroutput.statusCode
properties, and only handles the error if either any of those don't exist or the value there is equal or over 500.This has a field
status
set which thensentry-javascript/packages/node/src/integrations/tracing/express.ts
Lines 182 to 191 in 1048a43
Since the error thrown by
googleapis
containsstatus
field, the error is not logged to Sentry.On Express side the error propagates through
next(err)
calls until it reachesfinalhandler
(express source). In finalhandler if this last callback was called with an error, it gets the status code from.status
or.statusCode
properties, sets that to the response. If those fields don't exist it either uses the current status code in the response object or sets it to 500.The Sentry logic of also looking into
.status_code
in the Error object and ignoring errors based on it is inconsistent with this.Expected Result
Error to be captured.
Actual Result
Error not captured
Suggested fix
I do see the background of this default behavior in allowing application developers to throw all kinds of objects enabling application logic with middlewares responding with authentication errors/etc later on based on the status code. However a vast majority of errors thrown by 3rd party libraries are not well documented and thus should be able to be considered as opaque. With this default logic in place Sentry is quietly ignoring some of these errors often unexpectedly from the developers point of view.
I see the solution being
class MyAppError extends Error {}
instances and haveshouldHandleError: (err) => !(err instanceof MyAppError)
when they have ES6 support (or some other property magic if they're not)shouldHandleError
option or this behavior. Then the users could implement workaround like the one in 1. themselves.My favorite would be option 1. but you do you <3
The text was updated successfully, but these errors were encountered: