Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use middleware instead of method override to handle rescued exceptions
There are a few drawbacks to the method override approach: 1. It's hard to properly clean up the patched method after tests. This makes setting apps for different setups very hard. 2. We need to target specific middlewares to make it work. If there's another exception-rescuing middleware in the middle that isn't patched, the exception would still not be reported. See #738 So this commit inserts a new middleware for capturing rescued exceptions. It works like this: - The new middleware should be the last middleware of the app. - When `config.rails.report_rescued_exceptions = true` there's an exception raised 1. the exception will be stored in the request env under the `"sentry.rescued_exception"` key. 2. the CaptureExceptions middleware will detect that env and report the exception. - When `config.rails.report_rescued_exceptions = false` there's an exception raised - It doesn't store the exception in request env, so if the exception is captured by other middlewares, it won't be reported. Although the approach is very different than the old one, it should be able to solve the same problem and cause fewer bugs.
- Loading branch information