Skip to content

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

@lestephane

Description

@lestephane

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.

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions