Search in sources :

Example 1 with ErrorType

use of io.stackgres.common.ErrorType in project stackgres by ongres.

the class KubernetesExceptionMapper method toErrorTypeResponse.

private Response toErrorTypeResponse(Status status, String reason) {
    LOGGER.debug("Parsing StackGres validation error");
    ErrorType errorType = ErrorType.parseErrorType(reason);
    List<String> fields = new ArrayList<>();
    List<String> fieldCauses = new ArrayList<>();
    if (status.getDetails() != null) {
        final List<StatusCause> causes = status.getDetails().getCauses();
        if (causes != null) {
            causes.forEach(c -> {
                fields.add(c.getField());
                fieldCauses.add(c.getMessage());
            });
        }
    }
    final String detail = !fieldCauses.isEmpty() ? String.join("\n", fieldCauses) : status.getMessage();
    ErrorResponse response = new ErrorResponseBuilder(reason).setTitle(errorType.getTitle()).setDetail(detail).setStatus(status.getCode()).setFields(fields.toArray(new String[0])).build();
    return Response.status(status.getCode()).type(MediaType.APPLICATION_JSON).entity(response).build();
}
Also used : ErrorType(io.stackgres.common.ErrorType) ArrayList(java.util.ArrayList) StatusCause(io.fabric8.kubernetes.api.model.StatusCause)

Aggregations

StatusCause (io.fabric8.kubernetes.api.model.StatusCause)1 ErrorType (io.stackgres.common.ErrorType)1 ArrayList (java.util.ArrayList)1