
com.github.phillipkruger.apiee.providers.EntityNotFoundExceptionMapper Maven / Gradle / Ivy
package com.github.phillipkruger.apiee.providers;
import javax.persistence.EntityNotFoundException;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
/**
* Translate Java entity not found exceptions to HTTP response
* @author Phillip Kruger ([email protected])
*/
@Provider
public class EntityNotFoundExceptionMapper implements ExceptionMapper {
@Override
@Produces(MediaType.APPLICATION_JSON)
public Response toResponse(EntityNotFoundException entityNotFoundException) {
return Response.status(Response.Status.NOT_FOUND).header(REASON,entityNotFoundException.getMessage()).build();
}
private static final String REASON = "reason";
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy