Search in sources :

Example 96 with ExceptionHandler

use of org.springframework.web.bind.annotation.ExceptionHandler in project ArachneCentralAPI by OHDSI.

the class ExceptionHandlingController method exceptionHandler.

@ExceptionHandler(NotEmptyException.class)
public ResponseEntity<JsonResult> exceptionHandler(NotEmptyException ex) {
    LOGGER.error(ex.getMessage(), ex);
    JsonResult result = new JsonResult<>(DEPENDENCY_EXISTS);
    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 97 with ExceptionHandler

use of org.springframework.web.bind.annotation.ExceptionHandler in project ArachneCentralAPI by OHDSI.

the class ExceptionHandlingController method exceptionHandler.

@ExceptionHandler(FieldException.class)
public ResponseEntity<JsonResult> exceptionHandler(FieldException ex) {
    LOGGER.error(ex.getMessage(), ex);
    JsonResult result = new JsonResult<>(VALIDATION_ERROR);
    result.setErrorMessage("Incorrect data");
    result.getValidatorErrors().put(ex.getField(), 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 98 with ExceptionHandler

use of org.springframework.web.bind.annotation.ExceptionHandler 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 99 with ExceptionHandler

use of org.springframework.web.bind.annotation.ExceptionHandler in project ArachneCentralAPI by OHDSI.

the class ExceptionHandlingController method exceptionHandler.

@ExceptionHandler(IOException.class)
public ResponseEntity<JsonResult> exceptionHandler(IOException ex) {
    LOGGER.error(ex.getMessage(), ex);
    JsonResult result = new JsonResult<>(SYSTEM_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 100 with ExceptionHandler

use of org.springframework.web.bind.annotation.ExceptionHandler 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)

Aggregations

ExceptionHandler (org.springframework.web.bind.annotation.ExceptionHandler)178 ResponseEntity (org.springframework.http.ResponseEntity)58 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)48 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)41 HttpHeaders (org.springframework.http.HttpHeaders)39 ModelAndView (org.springframework.web.servlet.ModelAndView)33 ResponseEntityExceptionHandler (org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler)31 JsonResult (com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult)17 HttpStatus (org.springframework.http.HttpStatus)13 AjaxJson (com.cdeledu.common.base.AjaxJson)12 ResultModels (eu.bcvsolutions.idm.core.api.dto.ResultModels)8 DefaultErrorModel (eu.bcvsolutions.idm.core.api.exception.DefaultErrorModel)8 ErrorModel (eu.bcvsolutions.idm.core.api.exception.ErrorModel)8 RestResponse (org.entando.entando.web.common.model.RestResponse)8 ArrayList (java.util.ArrayList)7 BindingResult (org.springframework.validation.BindingResult)6 FieldError (org.springframework.validation.FieldError)5 ErrorInfo (com.haulmont.restapi.exception.ErrorInfo)4 PrintWriter (java.io.PrintWriter)4 StringWriter (java.io.StringWriter)4