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

[BUG] .configured(toMapExceptions().ofType(...)) does not map matching *checked* exception, calls default exception mapper with MethodInvocationException instead #10

Open
lestephane opened this issue Jul 17, 2019 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@lestephane
Copy link

lestephane commented Jul 17, 2019

Describe the bug
I mapped a checked exception to a specific mapper, but it is not called when a use case throws the exception. Instead, the default exception handler is called with an exception of type

com.envimate.messageMate.useCases.useCasesAdapter.methodInvoking.MethodInvocationException

To Reproduce

Setup an application exception mapper next to the default exception mapper, for a checked application exception (it only happens with checked exceptions)

public class ApplicationException extends Exception {
...
}
.configured(toMapExceptions()
  .ofType(ApplicationException.class).toResponsesUsing(caughtExceptionMapper)
  .ofAllRemainingTypesUsing(uncaughtExceptionMapper)

Cause the exception to occur in the invoked use case

public Response invoke(
  final Requet request)
    throws ApplicationException {
  ...
  return optional.orElseThrow(ApplicationException.class);
}

The uncaughtExceptionHandler is called with

com.envimate.messageMate.useCases.useCaseAdapter.methodInvoking.MethodInvocationException: Could not call method public ...
-> cause: java.lang.reflect.InvocationTargetException
  -> target: ...ApplicationException

Expected behavior

The caughtExceptionMapper should be called.

I masked my real class names, but please do ask if you need more details.

@lestephane lestephane added the bug Something isn't working label Jul 17, 2019
@lestephane
Copy link
Author

Looks like some unwrapping of the reflective invocation exception cause needs to happen when determining the exception mapper to invoke.

@lestephane lestephane changed the title [BUG] .configured(toMapExceptions().ofType(...)) does not map matching exception, calls default exception mapper with MethodInvocationException instead [BUG] .configured(toMapExceptions().ofType(...)) does not map matching *checked* exception, calls default exception mapper with MethodInvocationException instead Jul 17, 2019
@lestephane
Copy link
Author

Switching the type of the exception to RuntimeException fixes the problem, adjusted the title of the issue and reproduction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants