Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added unique constraints for entities #1073

Merged
merged 10 commits into from
May 17, 2019
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,25 @@

@Provider
public class GenericExceptionMapper implements ExceptionMapper<Throwable> {

private final String DETAIL = "Detail: ";

@Override
public Response toResponse(Throwable ex) {
ErrorMessage errorMessage = new ErrorMessage(ex);
StringWriter errorStackTrace = new StringWriter();
ex.printStackTrace(new PrintWriter(errorStackTrace));
Status responseStatus;
if(ex instanceof DataIntegrityViolationException) {
responseStatus = Status.CONFLICT;
String cause = ex.getCause().getCause().getMessage();
cause = cause.substring(cause.indexOf(DETAIL) + DETAIL.length());
ex = new RuntimeException(cause);
} else if (ex instanceof NotFoundException) {
responseStatus = Status.NOT_FOUND;
} else {
responseStatus = Status.INTERNAL_SERVER_ERROR;
}

ErrorMessage errorMessage = new ErrorMessage(ex);
return Response.status(responseStatus)
.entity(errorMessage)
.type(MediaType.APPLICATION_JSON)
Expand Down
Loading