Closed
Description
Previous solution:
Sentry.setupNestErrorHandler()
in main file.- Errors are sent to Sentry by proxying the nest base exception filter adding a
captureException
call and then using the proxy as a global filter. - Aside from being not very native to nest this approach had several issues, for example stopping user-defined global exception filters from working.
Attempted updates:
- Global exception filter extending base exception filter:
- Call
captureException
in a global error handler that catches all unhandled exceptions (should work with an empty@Catch()
decorator on the filter). - According to what I understood from the docs this approach should work just fine but it didn't. NestJS does not allow chaining of exception filters, so according to some rules exactly one exception filter is determined that will be called. The first filter that should be called is the most specific filter. However, this is not the case if introduced in the
setupNestErrorHandler
method. Rather, the global exception filter always overwrote user-defined global exception filters.
- Call
- Interceptor:
- Call
captureException
in a global interceptor. - The problem is that in nest interceptors are called before exception filters. So for example even if a user defines an exception filter to catch a specific exception type, the exception will still be logged to Sentry. So this approach kind of works, but is not really what we want, because it would produce a lot of noise for users.
- Call
Final solution:
- Ported the existing code to a nestjs root module.
- Initially just meant as a setup improvement (much more native to nest), but had the nice side-effect of working properly with user-defined local and global exception filters.