Search in sources :

Example 11 with VALIDATION_ERROR

use of com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult.ErrorCode.VALIDATION_ERROR in project ArachneCentralAPI by OHDSI.

the class ExceptionHandlingController method exceptionHandler.

@ExceptionHandler(ValidationException.class)
public ResponseEntity<JsonResult> exceptionHandler(ValidationException ex) {
    LOGGER.warn(ex.getMessage());
    JsonResult result = new JsonResult<>(VALIDATION_ERROR);
    result.setErrorMessage(ex.getMessage());
    return new ResponseEntity<>(result, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler)

Example 12 with VALIDATION_ERROR

use of com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult.ErrorCode.VALIDATION_ERROR in project ArachneCentralAPI by OHDSI.

the class ExceptionHandlingController method exceptionHandler.

@ExceptionHandler(BindException.class)
public ResponseEntity<JsonResult> exceptionHandler(BindException ex) {
    LOGGER.warn(ex.getMessage());
    JsonResult result = new JsonResult<>(VALIDATION_ERROR);
    result.setErrorMessage("Incorrect data");
    if (ex.hasErrors()) {
        ex.getFieldErrors().forEach(er -> result.getValidatorErrors().put(er.getField(), er.getDefaultMessage()));
    }
    return new ResponseEntity<>(result, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler)

Example 13 with VALIDATION_ERROR

use of com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult.ErrorCode.VALIDATION_ERROR in project ArachneCentralAPI by OHDSI.

the class ExceptionHandlingController method exceptionHandler.

@ExceptionHandler(MethodArgumentNotValidException.class)
public ResponseEntity<JsonResult> exceptionHandler(MethodArgumentNotValidException ex) {
    LOGGER.warn(ex.getMessage());
    JsonResult result = new JsonResult<>(VALIDATION_ERROR);
    if (ex.getBindingResult().hasErrors()) {
        result = setValidationErrors(ex.getBindingResult());
    }
    return new ResponseEntity<>(result, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler)

Aggregations

JsonResult (com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult)12 ResponseEntity (org.springframework.http.ResponseEntity)9 ExceptionHandler (org.springframework.web.bind.annotation.ExceptionHandler)9 ApiOperation (io.swagger.annotations.ApiOperation)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 GET (org.springframework.web.bind.annotation.RequestMethod.GET)2 POST (org.springframework.web.bind.annotation.RequestMethod.POST)2 PUT (org.springframework.web.bind.annotation.RequestMethod.PUT)2 ArachnePasswordInfoDTO (com.odysseusinc.arachne.commons.api.v1.dto.ArachnePasswordInfoDTO)1 PERMISSION_DENIED (com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult.ErrorCode.PERMISSION_DENIED)1 InvitationActionWithTokenDTO (com.odysseusinc.arachne.portal.api.v1.dto.InvitationActionWithTokenDTO)1 UpdateNotificationDTO (com.odysseusinc.arachne.portal.api.v1.dto.UpdateNotificationDTO)1 AlreadyExistException (com.odysseusinc.arachne.portal.exception.AlreadyExistException)1 NotExistException (com.odysseusinc.arachne.portal.exception.NotExistException)1 PasswordValidationException (com.odysseusinc.arachne.portal.exception.PasswordValidationException)1 ValidationException (com.odysseusinc.arachne.portal.exception.ValidationException)1 AnalysisUnlockRequest (com.odysseusinc.arachne.portal.model.AnalysisUnlockRequest)1 IUser (com.odysseusinc.arachne.portal.model.IUser)1 Date (java.util.Date)1 UUID (java.util.UUID)1