Description
- Review the documentation: https://docs.sentry.io/
- Search for existing issues: https://github.com/getsentry/sentry-javascript/issues
- Use the latest release: https://github.com/getsentry/sentry-javascript/releases
Package + Version
-
@sentry/browser
-
@sentry/node
-
raven-js
-
raven-node
(raven for node) - other:
Version:
4.6.3
Description
When I enable Sentry.Handlers.requestHandler()
(in Express), asynchronous errors will be:
- (expected) reported to Sentry
- (unexpected) passed on to my Express error handling middleware
It took me a very long time to understand why an async error inside a request handler would lead to different behaviour in development vs production.
In development the error would cause the process to die/exit (default behaviour in Node), whereas in production the error would be passed on to my error handling middleware, and an error response would be sent. It turned out this was because we were only enabling the request handler in production.
I would like to question whether "passing the error to error handling middleware (by calling next
and passing the error )" is really the job of Sentry.Handlers.requestHandler()
. Perhaps it should only report the error? After all, that's the main reason to enable Sentry in an application. This way, conditionally enabling Sentry (e.g. depending on env) would not lead to any other unexpected behaviour changes, such as the one I described above.
Alternatively, if we think it is the right thing to do, we should document it clearly, along with a suggestion for how to achieve consistent behaviour when the request handler is not enabled (e.g. by using domains like how Sentry.Handlers.requestHandler()
does it).