Skip to content

Commit

Permalink
add workaround for custom ValidationExceptionMapper overriding the de…
Browse files Browse the repository at this point in the history
…fault ValidationExceptionMapper
  • Loading branch information
Gael Abadin committed Jul 23, 2024
1 parent 70187e6 commit 0fd3bc2
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.payara.hello;

import jakarta.ejb.EJBException;
import jakarta.validation.ValidationException;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper;
Expand All @@ -16,6 +17,9 @@ public class EJBExceptionMapper implements ExceptionMapper<EJBException> {
@Context
private Providers providers;

@Context
private ValidationExceptionMapper validationExceptionMapper;

@Override
public Response toResponse(final EJBException exception) {

Expand All @@ -29,6 +33,9 @@ public Response toResponse(final EJBException exception) {
handledException = e;
}

if (handledException instanceof ValidationException) {
return validationExceptionMapper.toResponse((ValidationException) handledException);
}
ExceptionMapper<Throwable> mapper = providers.getExceptionMapper((Class<Throwable>) handledException.getClass());
return mapper.toResponse(handledException);
}
Expand Down

0 comments on commit 0fd3bc2

Please sign in to comment.