In our (legacy) codebase, we're throwing WebApplicationExceptions in different ways. In an attempt to make some order in how we're handling exceptions - I wanted to create an ExceptionMapper for these WAEs (and others).
I realized, however, that Jersey's ExceptionMapper only maps WAE which weren't thrown with an entity.
For example:
throw new WebApplicationException(Response.status(500).build());
This exception is caught by the ExceptionMapper.
throw new WebApplicationException(Response.status(500).entity(WsResourceUtils.createWSResourceRestError(500, "bla")).build());
This exception is NOT caught by the ExceptionMapper.
Both are thrown from the same point in code.
This is my ExceptionMapper:
@Provider
public class GeneralExceptionMapper implements ExceptionMapper<Throwable> {
private static final Logger logger = LoggerFactory.getLogger(GeneralExceptionMapper.class);
@Override
public Response toResponse(Throwable e) {
logger.error("Caught a WAE", e);
...
}
Is it possible to create an ExceptionMapper which will catch WebApplicationExceptions even if their response is already built with an entity?
We're using Jersey 1.17.
Thanks.