Search in sources :

Example 6 with ErrorListItemDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.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;
}
Also used : ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) ConstraintViolation(javax.validation.ConstraintViolation) ArrayList(java.util.ArrayList) ErrorListItemDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorListItemDTO)

Aggregations

ArrayList (java.util.ArrayList)3 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)3 ErrorListItemDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorListItemDTO)3 ErrorListItemDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ErrorListItemDTO)3 ErrorHandler (org.wso2.carbon.apimgt.api.ErrorHandler)2 ConstraintViolation (javax.validation.ConstraintViolation)1 Test (org.testng.annotations.Test)1