use of org.wso2.carbon.apimgt.rest.api.common.dto.ErrorListItemDTO in project carbon-apimgt by wso2.
the class RestApiUtil method getConstraintViolationErrorDTO.
public static <T> ErrorDTO getConstraintViolationErrorDTO(Set<ConstraintViolation<T>> violations) {
ErrorDTO errorDTO = new ErrorDTO();
errorDTO.setDescription("Validation Error");
errorDTO.setMessage("Bad Request");
errorDTO.setCode(400l);
errorDTO.setMoreInfo("");
List<ErrorListItemDTO> errorListItemDTOs = new ArrayList<>();
for (ConstraintViolation violation : violations) {
ErrorListItemDTO errorListItemDTO = new ErrorListItemDTO();
errorListItemDTO.setCode(400 + "_" + violation.getPropertyPath());
errorListItemDTO.setMessage(violation.getPropertyPath() + ": " + violation.getMessage());
errorListItemDTOs.add(errorListItemDTO);
}
errorDTO.setError(errorListItemDTOs);
return errorDTO;
}
Aggregations