Skip to content

Instantly share code, notes, and snippets.

@lefloh
Last active November 28, 2016 07:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lefloh/35be1c0a4693e5ad157e1568992f8c43 to your computer and use it in GitHub Desktop.
Save lefloh/35be1c0a4693e5ad157e1568992f8c43 to your computer and use it in GitHub Desktop.
WebApplicationExceptionMapper
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
@Provider
public class WebApplicationExceptionMapper implements ExceptionMapper<WebApplicationException> {
private static final Logger LOG = LoggerFactory.getLogger(WebApplicationExceptionMapper.class);
@Override
public Response toResponse(WebApplicationException exception) {
int status = exception.getResponse().getStatus();
if (status >= 400 && status < 500) {
LOG.warn("Client error {}: {}", status, exception.getMessage());
} else {
LOG.error("Error {}", status, exception);
}
return exception.getResponse();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment