Last active
November 28, 2016 07:39
-
-
Save lefloh/35be1c0a4693e5ad157e1568992f8c43 to your computer and use it in GitHub Desktop.
WebApplicationExceptionMapper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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