Skip to content

UnwrapException ineffective when a subclass of the declared exception is mapped via ServerExceptionMapper #48197

@kevinferrare

Description

@kevinferrare

Describe the bug

I am trying to use UnwrapException annotation for an exception type which parent is also mapped in an exception mapper via ServerExceptionMapper:

@UnwrapException({ WebApplicationException.class })
public class ExceptionsMappers {
  @ServerExceptionMapper
  public RestResponse<Error> mapUnhandledException(RuntimeException ex) {
    // Custom error for any other unhandled exceptions
    ...
  }

  @ServerExceptionMapper
  public RestResponse<Error> mapJsonProcessingException(JsonProcessingException ex) {
    // Custom error for jackson parsing issues, usually wrapped into WebApplicationException
    ...
  }
}

This makes UnwrapException ineffective because I guess it matches WebApplicationException as RuntimeException which is already mapped in mapUnhandledException, and as stated in the javadoc:

Unwrapping means that when an Exception of the configured type is thrown and no jakarta.ws.rs.ext.ExceptionMapper exists, then RESTEasy Reactive will attempt to locate an ExceptionMapper for the cause of the Exception.

Is this the expected behaviour?
In that case, is there a way to use UnwrapException while also providing custom error messages for unhandled cases?

If not, can this be improved?

Expected behavior

No response

Actual behavior

No response

How to Reproduce?

No response

Output of uname -a or ver

6.11.0-26-generic #26~24.04.1-Ubuntu

Output of java -version

java version "21.0.4" 2024-07-16 LTS

Quarkus version or git rev

3.20.0.redhat-00002

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.9.9

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions