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();
}
Aggregations