use of com.yahoo.elide.core.exceptions.ForbiddenAccessException in project elide by yahoo.
the class QueryRunner method handleRuntimeException.
public static ElideResponse handleRuntimeException(Elide elide, RuntimeException error, boolean isVerbose) {
CustomErrorException mappedException = elide.mapError(error);
ObjectMapper mapper = elide.getMapper().getObjectMapper();
if (mappedException != null) {
return buildErrorResponse(mapper, mappedException, isVerbose);
}
if (error instanceof WebApplicationException) {
WebApplicationException e = (WebApplicationException) error;
log.debug("WebApplicationException", e);
String body = e.getResponse().getEntity() != null ? e.getResponse().getEntity().toString() : e.getMessage();
return ElideResponse.builder().responseCode(e.getResponse().getStatus()).body(body).build();
}
if (error instanceof HttpStatusException) {
HttpStatusException e = (HttpStatusException) error;
if (e instanceof ForbiddenAccessException) {
if (log.isDebugEnabled()) {
log.debug("{}", ((ForbiddenAccessException) e).getLoggedMessage());
}
} else {
log.debug("Caught HTTP status exception {}", e.getStatus(), e);
}
return buildErrorResponse(mapper, new HttpStatusException(200, e.getMessage()) {
@Override
public int getStatus() {
return 200;
}
@Override
public Pair<Integer, JsonNode> getErrorResponse() {
return e.getErrorResponse();
}
@Override
public Pair<Integer, JsonNode> getVerboseErrorResponse() {
return e.getVerboseErrorResponse();
}
@Override
public String getVerboseMessage() {
return e.getVerboseMessage();
}
@Override
public String toString() {
return e.toString();
}
}, isVerbose);
}
if (error instanceof ConstraintViolationException) {
ConstraintViolationException e = (ConstraintViolationException) error;
log.debug("Constraint violation exception caught", e);
String message = "Constraint violation";
final ErrorObjects.ErrorObjectsBuilder errorObjectsBuilder = ErrorObjects.builder();
for (ConstraintViolation<?> constraintViolation : e.getConstraintViolations()) {
errorObjectsBuilder.addError().withDetail(constraintViolation.getMessage());
final String propertyPathString = constraintViolation.getPropertyPath().toString();
if (!propertyPathString.isEmpty()) {
Map<String, Object> source = new HashMap<>(1);
source.put("property", propertyPathString);
errorObjectsBuilder.with("source", source);
}
}
return buildErrorResponse(mapper, new CustomErrorException(HttpStatus.SC_OK, message, errorObjectsBuilder.build()), isVerbose);
}
log.error("Error or exception uncaught by Elide", error);
throw new RuntimeException(error);
}
Aggregations