Search in sources :

Example 66 with ExceptionHandler

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

the class RestTechnicalExceptionHandler method paaSDeploymentErrorHandler.

@ExceptionHandler(value = PaaSDeploymentException.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ResponseBody
public RestResponse<Void> paaSDeploymentErrorHandler(PaaSDeploymentException e) {
    log.warn("Error in PaaS Deployment", e);
    RestErrorCode errorCode = RestErrorCode.APPLICATION_DEPLOYMENT_ERROR;
    if (e.getPassErrorCode() != null) {
        errorCode = e.getPassErrorCode();
    }
    return RestResponseBuilder.<Void>builder().error(RestErrorBuilder.builder(errorCode).message("Application cannot be deployed " + e.getMessage()).build()).build();
}
Also used : RestErrorCode(alien4cloud.rest.model.RestErrorCode) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 67 with ExceptionHandler

use of org.springframework.web.bind.annotation.ExceptionHandler in project wechat by dllwh.

the class GlobalExceptionHandler method requestTypeMismatch.

/**
 * 400 - Bad Request
 */
@ResponseBody
@ExceptionHandler(TypeMismatchException.class)
public AjaxJson requestTypeMismatch(TypeMismatchException ex) {
    AjaxJson result = new AjaxJson();
    if (logger.isDebugEnabled()) {
        logger.error("TypeMismatchException", ex);
    }
    result.setSuccess(false);
    result.setMsg(ex.getMessage());
    result.setResultCode(400);
    return result;
}
Also used : AjaxJson(com.cdeledu.common.base.AjaxJson) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 68 with ExceptionHandler

use of org.springframework.web.bind.annotation.ExceptionHandler in project wechat by dllwh.

the class GlobalExceptionHandler method handleMethodArgumentNotValidException.

/**
 * 400 - Bad Request
 */
@ResponseBody
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(MethodArgumentNotValidException.class)
public AjaxJson handleMethodArgumentNotValidException(final MethodArgumentNotValidException e) {
    AjaxJson result = new AjaxJson();
    if (logger.isDebugEnabled()) {
        logger.error("MethodArgumentNotValidException", e);
    }
    result.setSuccess(false);
    result.setMsg(e.getMessage());
    result.setResultCode(400);
    return result;
}
Also used : AjaxJson(com.cdeledu.common.base.AjaxJson) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 69 with ExceptionHandler

use of org.springframework.web.bind.annotation.ExceptionHandler in project wechat by dllwh.

the class GlobalExceptionHandler method nullPointerExceptionHandler.

/**
 * @方法:空指针异常
 * @创建人:独泪了无痕
 * @param ex
 */
@ResponseBody
@ExceptionHandler(NullPointerException.class)
public AjaxJson nullPointerExceptionHandler(NullPointerException ex) {
    AjaxJson ajaxJson = new AjaxJson();
    if (logger.isDebugEnabled()) {
        logger.error("空指针异常:", ex);
    }
    ajaxJson.setSuccess(false);
    ajaxJson.setResultCode(500);
    ajaxJson.setMsg(NullPointerException.class.getName());
    return ajaxJson;
}
Also used : AjaxJson(com.cdeledu.common.base.AjaxJson) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 70 with ExceptionHandler

use of org.springframework.web.bind.annotation.ExceptionHandler in project wechat by dllwh.

the class GlobalExceptionHandler method httpMessageNotWritableException.

/**
 * 500 - Internal Server Error
 */
@ResponseBody
@ExceptionHandler(HttpMessageNotWritableException.class)
public AjaxJson httpMessageNotWritableException(HttpMessageNotWritableException e) {
    AjaxJson result = new AjaxJson();
    if (logger.isDebugEnabled()) {
        logger.error(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(), e);
    }
    result.setSuccess(false);
    result.setMsg(e.getMessage());
    result.setResultCode(500);
    return result;
}
Also used : AjaxJson(com.cdeledu.common.base.AjaxJson) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

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