Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggested change to fix logging of handled exceptions #166

Conversation

TobiasMende
Copy link

@TobiasMende TobiasMende commented Jul 20, 2021

I had an idea how to fix #156 and would love some feedback on this approach. If the approach looks okay to you, I would spend some more time to add tests to verify the changed behaviour (namely @ResponseStatus exceptions and @ExceptionHandler methods get to handle the exception first and therefore can prevent BugSnag from logging it).

Goal

Fix #156

Design

Just changing the Order of the BugsnagMvcExceptionHandler does not work, because all the three exception handlers have the same (lowest) precedence but are grouped in the HandlerExceptionResolverComposite. This approach injects BugSnag as the second last exception handler just before the DefaultHandlerExceptionResolver.

Changeset

The BugsnagMvcExceptionHandler is injected manually at the right position and not by Spring ordering.

Testing

Existing tests still pass. I added two new test to test that exceptions handled by @ResponseStatus and @ExceptionHandler are not sent to BugSnag.

@johnkiely1
Copy link
Member

Hi @TobiasMende,

Thanks for the PR, we will take a look at this as soon as priorities allow.

@TobiasMende
Copy link
Author

@johnkiely1 Cool! I am looking forward to your feedback. Meanwhile I have added two tests, to verify the behaviour.

@TobiasMende TobiasMende force-pushed the 156-place-bugnsag-resolver-just-before-default-handler branch from 2ac8f75 to a5e903a Compare July 21, 2021 13:17
*/
@Override
public void extendHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers) {
final int position = exceptionResolvers.isEmpty() ? 0 : exceptionResolvers.size() - 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can tell the default exception resolvers are populated here.

My concern with this approach is that we don't have any control over the contents of this list. If the order or content of the default exception handlers is changed in the spring libraries then it could affect the way that the Bugsnag library works. If it does then we might end up in the situation of trying to support multiple versions of this mechanism as we can't guarantee what versions of the spring framework users are using.

Although there are problems with the current implementation, I believe that it is more resilient to change in the framework, and it's still possible to exclude unwanted exceptions using the beforeNotify callback, or by specifying "Discard by error class" in the project settings.

@TobiasMende TobiasMende closed this Mar 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix redundant exception handling
3 participants