Search in sources :

Example 86 with ExceptionHandler

use of org.springframework.web.bind.annotation.ExceptionHandler in project dhis2-core by dhis2.

the class CsdController method soapError.

@ExceptionHandler
public void soapError(SoapException ex, HttpServletResponse response) throws JAXBException, IOException {
    Envelope envelope = new Envelope();
    envelope.setHeader(null);
    envelope.getBody().setFault(new Fault());
    envelope.getBody().getFault().getCode().getValue().setValue(ex.getFaultCode());
    envelope.getBody().getFault().getReason().getText().setValue(ex.getMessage());
    response.setContentType(SOAP_CONTENT_TYPE);
    marshaller.marshal(envelope, response.getOutputStream());
}
Also used : Fault(org.hisp.dhis.web.ohie.common.domain.soap.Fault) Envelope(org.hisp.dhis.web.ohie.common.domain.soap.Envelope) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler)

Example 87 with ExceptionHandler

use of org.springframework.web.bind.annotation.ExceptionHandler in project cuba by cuba-platform.

the class RestControllerExceptionHandler method handleException.

@ExceptionHandler(Exception.class)
@ResponseBody
public ResponseEntity<ErrorInfo> handleException(Exception e) {
    log.error("Exception in REST controller", e);
    ErrorInfo errorInfo = new ErrorInfo("Server error", "");
    return new ResponseEntity<>(errorInfo, HttpStatus.INTERNAL_SERVER_ERROR);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ErrorInfo(com.haulmont.restapi.exception.ErrorInfo) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 88 with ExceptionHandler

use of org.springframework.web.bind.annotation.ExceptionHandler in project cuba by cuba-platform.

the class RestControllerExceptionHandler method handleCustomValidationException.

@ExceptionHandler(CustomValidationException.class)
@ResponseBody
public ResponseEntity<List<ConstraintViolationInfo>> handleCustomValidationException(CustomValidationException e) {
    log.debug("CustomValidationException: {}", e.getMessage());
    ConstraintViolationInfo errorInfo = new ConstraintViolationInfo();
    errorInfo.setPath("");
    errorInfo.setInvalidValue(null);
    errorInfo.setMessage(e.getLocalizedMessage());
    errorInfo.setMessageTemplate("{com.haulmont.cuba.core.global.validation.CustomValidationException}");
    return new ResponseEntity<>(Collections.singletonList(errorInfo), HttpStatus.BAD_REQUEST);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ConstraintViolationInfo(com.haulmont.restapi.exception.ConstraintViolationInfo) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 89 with ExceptionHandler

use of org.springframework.web.bind.annotation.ExceptionHandler in project cuba by cuba-platform.

the class RestControllerExceptionHandler method handleRowLevelSecurityException.

@ExceptionHandler(RowLevelSecurityException.class)
@ResponseBody
public ResponseEntity<ErrorInfo> handleRowLevelSecurityException(RowLevelSecurityException e) {
    log.error("RowLevelSecurityException in service", e);
    ErrorInfo errorInfo = new ErrorInfo("Forbidden", e.getMessage());
    return new ResponseEntity<>(errorInfo, HttpStatus.FORBIDDEN);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ErrorInfo(com.haulmont.restapi.exception.ErrorInfo) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 90 with ExceptionHandler

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

the class ExceptionHandlingController method exceptionHandler.

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

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