org.accidia.echo.resources.exceptions.IllegalArgumentExceptionMapper Maven / Gradle / Ivy
package org.accidia.echo.resources.exceptions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
@Provider
public class IllegalArgumentExceptionMapper implements ExceptionMapper {
private static final Logger logger = LoggerFactory.getLogger(IllegalArgumentExceptionMapper.class);
@Override
public Response toResponse(final IllegalArgumentException exception) {
logger.debug("toResponse(exception)");
logger.info("illegal argument exception: {}", exception);
return Response
.status(Response.Status.BAD_REQUEST)
.entity(exception.getMessage())
.type(MediaType.TEXT_PLAIN).build();
}
}