use of io.crnk.core.engine.error.JsonApiExceptionMapper in project crnk-framework by crnk-project.
the class AbstractWrappedExceptionMapper method toErrorResponse.
@Override
public ErrorResponse toErrorResponse(E exception) {
Throwable cause = exception.getCause();
if (cause != null) {
Optional<JsonApiExceptionMapper> mapper = context.getExceptionMapperRegistry().findMapperFor(cause.getClass());
if (mapper.isPresent()) {
return mapper.get().toErrorResponse(cause);
}
}
LOGGER.error("failed to process request due to jpa exception", exception);
// no mapper found, return default error
int status = getStatus();
ErrorData errorData = ErrorData.builder().setStatus(Integer.toString(status)).setTitle(exception.getMessage()).build();
return ErrorResponse.builder().setSingleErrorData(errorData).setStatus(status).build();
}
Aggregations