Search in sources :

Example 1 with ErrorResponse

use of com.netflix.conductor.common.validation.ErrorResponse in project conductor by Netflix.

the class ValidationExceptionMapper method toErrorResponse.

private static ErrorResponse toErrorResponse(ValidationException ve) {
    if (ve instanceof ConstraintViolationException) {
        return constraintViolationExceptionToErrorResponse((ConstraintViolationException) ve);
    } else {
        ErrorResponse result = new ErrorResponse();
        result.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
        result.setMessage(ve.getMessage());
        return result;
    }
}
Also used : ConstraintViolationException(javax.validation.ConstraintViolationException) ErrorResponse(com.netflix.conductor.common.validation.ErrorResponse)

Example 2 with ErrorResponse

use of com.netflix.conductor.common.validation.ErrorResponse in project conductor by Netflix.

the class ValidationExceptionMapper method constraintViolationExceptionToErrorResponse.

private static ErrorResponse constraintViolationExceptionToErrorResponse(ConstraintViolationException exception) {
    ErrorResponse errorResponse = new ErrorResponse();
    errorResponse.setStatus(Response.Status.BAD_REQUEST.getStatusCode());
    errorResponse.setMessage("Validation failed, check below errors for detail.");
    List<ValidationError> validationErrors = new ArrayList<>();
    exception.getConstraintViolations().forEach(e -> validationErrors.add(new ValidationError(getViolationPath(e), e.getMessage(), getViolationInvalidValue(e.getInvalidValue()))));
    errorResponse.setValidationErrors(validationErrors);
    return errorResponse;
}
Also used : ArrayList(java.util.ArrayList) ValidationError(com.netflix.conductor.common.validation.ValidationError) ErrorResponse(com.netflix.conductor.common.validation.ErrorResponse)

Example 3 with ErrorResponse

use of com.netflix.conductor.common.validation.ErrorResponse in project conductor by Netflix.

the class ClientBase method handleUniformInterfaceException.

private void handleUniformInterfaceException(UniformInterfaceException exception, URI uri) {
    ClientResponse clientResponse = exception.getResponse();
    if (clientResponse == null) {
        throw new ConductorClientException(String.format("Unable to invoke Conductor API with uri: %s", uri));
    }
    try {
        if (clientResponse.getStatus() < 300) {
            return;
        }
        String errorMessage = clientResponse.getEntity(String.class);
        logger.error("Unable to invoke Conductor API with uri: {}, unexpected response from server: statusCode={}, responseBody='{}'.", uri, clientResponse.getStatus(), errorMessage);
        ErrorResponse errorResponse;
        try {
            errorResponse = objectMapper.readValue(errorMessage, ErrorResponse.class);
        } catch (IOException e) {
            throw new ConductorClientException(clientResponse.getStatus(), errorMessage);
        }
        throw new ConductorClientException(clientResponse.getStatus(), errorResponse);
    } catch (ConductorClientException e) {
        throw e;
    } catch (ClientHandlerException e) {
        handleClientHandlerException(e, uri);
    } catch (RuntimeException e) {
        handleRuntimeException(e, uri);
    } finally {
        clientResponse.close();
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) ClientHandlerException(com.sun.jersey.api.client.ClientHandlerException) IOException(java.io.IOException) ConductorClientException(com.netflix.conductor.client.exceptions.ConductorClientException) ErrorResponse(com.netflix.conductor.common.validation.ErrorResponse)

Aggregations

ErrorResponse (com.netflix.conductor.common.validation.ErrorResponse)3 ConductorClientException (com.netflix.conductor.client.exceptions.ConductorClientException)1 ValidationError (com.netflix.conductor.common.validation.ValidationError)1 ClientHandlerException (com.sun.jersey.api.client.ClientHandlerException)1 ClientResponse (com.sun.jersey.api.client.ClientResponse)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 ConstraintViolationException (javax.validation.ConstraintViolationException)1