Let's say we have @RestControllerAdvice
-annotated class like this:
@RestControllerAdvice
public class RestResponseExceptionHandler {
@ExceptionHandler(MyBusinessException .class)
public ResponseEntity<ErrorResponse> handleMyBusinessException (MyBusinessException ex) {
return createResponseEntity(ex, ex.getErrorCode());
}
@ExceptionHandler({IllegalArgumentException.class, ValidationException.class, DataIntegrityViolationException.class})
public ResponseEntity<ErrorResponse> handleInvalidPropertyException(RuntimeException ex) {
return createResponseEntity(ex, ErrorCode.DATA_INVALID);
}
[...]
@ExceptionHandler(RuntimeException.class)
public ResponseEntity<ErrorResponse> handleRuntimeException(RuntimeException ex) {
return createResponseEntity(ex, ErrorCode.UNKNOWN);
}
@ExceptionHandler(Exception.class)
public ResponseEntity<ErrorResponse> handleException(Exception ex) {
return createResponseEntity(ex, ErrorCode.UNKNOWN);
}
@ExceptionHandler(WrapperException .class)
public ResponseEntity<ErrorResponse> handleWrapperException (WrapperException ex) {
Exception exception = ex.getWrappedException();
// re-dispatch exception here
}
}
For a known WrapperException
, is it possible to somehow re-dispatch the wrapped exception?
I tried several things, e.g. rethrowing the wrapped excption or explicitly call a custom method of our ErrorController and re-throw the exception there, but so far no luck.