use of com.yahoo.elide.core.exceptions.ErrorObjects in project elide by yahoo.
the class QueryRunner method buildErrorResponse.
public static ElideResponse buildErrorResponse(ObjectMapper mapper, HttpStatusException error, boolean isVerbose) {
JsonNode errorNode;
if (!(error instanceof CustomErrorException)) {
// get the error message and optionally encode it
String errorMessage = isVerbose ? error.getVerboseMessage() : error.getMessage();
errorMessage = Encode.forHtml(errorMessage);
ErrorObjects errors = ErrorObjects.builder().addError().with("message", errorMessage).build();
errorNode = mapper.convertValue(errors, JsonNode.class);
} else {
errorNode = isVerbose ? error.getVerboseErrorResponse().getRight() : error.getErrorResponse().getRight();
}
String errorBody;
try {
errorBody = mapper.writeValueAsString(errorNode);
} catch (JsonProcessingException e) {
errorBody = errorNode.toString();
}
return ElideResponse.builder().responseCode(error.getStatus()).body(errorBody).build();
}
Aggregations