I have an exception mapper as following
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
@Provider
public class NotFoundMapper implements ExceptionMapper<NotFoundException> {
private final Logger log = LoggerFactory.getLogger(getClass());
private final MapperResponseBuilder responseBuilder = new MapperResponseBuilder();
@Override
public Response toResponse(NotFoundException ex) {
log.warn("NotFoundException : " + ex.getMessage(), ex);
return responseBuilder.buildErrorResponse(ex.getMessage(), Status.BAD_REQUEST);
}
}
So the NotFoundException is a RuntimeException. I would like to have 3 exception mappers, which maps
Is there any way to priorities those ?
It already runs with that priority. The most specific one is hit.
From the JAX-RS spec
When choosing an exception mapping provider to map an exception, an implementation MUST use the provider whose generic type is the nearest superclass of the exception.
If I am not understanding your question correctly, and instead you are wanting all three mappers to get hit, that won't happen. Only one mapper hit per request. It's a safety mechanism to avoid infinite loops.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With