Search in sources :

Example 1 with ErrorObjects

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();
}
Also used : ErrorObjects(com.yahoo.elide.core.exceptions.ErrorObjects) JsonNode(com.fasterxml.jackson.databind.JsonNode) CustomErrorException(com.yahoo.elide.core.exceptions.CustomErrorException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 CustomErrorException (com.yahoo.elide.core.exceptions.CustomErrorException)1 ErrorObjects (com.yahoo.elide.core.exceptions.ErrorObjects)1