@Provider
public final class RuntimeExceptionMapper
implements ExceptionMapper<RuntimeException> {
@Override
public Response toResponse(@NotNull final RuntimeException e) {
if (e instanceof WebApplicationException) {
return ((WebApplicationException) e).getResponse();
}
...
}
...
}
From: Gustavo Garcia [mailto:ggb_at_tokbox.com]
Sent: Tuesday, July 01, 2014 1:52 AM
To: users_at_jersey.java.net
Subject: [Jersey] Avoiding HTML response on unexpected exceptions
What is the best way to avoid jersey returning a HTML response with the error when an unexpected exception happens (i.e NullPointerException) ?
I tried creating a ExceptionMapper for Exception and it works but it means that I loose the default exception mapping for javax.ws.rs.WebApplicationException exceptions that is also quite bad.
What are the best practices here?
Thx a lot