Search in sources :

Example 71 with ExceptionHandler

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

the class GlobalExceptionHandler method handleBindException.

/**
 * 400 - Bad Request
 */
@ResponseBody
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(BindException.class)
public AjaxJson handleBindException(final BindException e) {
    AjaxJson result = new AjaxJson();
    if (logger.isDebugEnabled()) {
        logger.error("BindException", 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 72 with ExceptionHandler

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

the class GlobalExceptionHandler method conversionNotSupportedException.

/**
 * 500 - Internal Server Error
 */
@ResponseBody
@ExceptionHandler(ConversionNotSupportedException.class)
public AjaxJson conversionNotSupportedException(ConversionNotSupportedException 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)

Example 73 with ExceptionHandler

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

the class GlobalExceptionHandler method request406.

/**
 * 406 - Not Acceptable
 */
@ResponseBody
@ExceptionHandler(HttpMediaTypeNotAcceptableException.class)
public AjaxJson request406(HttpMediaTypeNotAcceptableException e) {
    AjaxJson result = new AjaxJson();
    if (logger.isDebugEnabled()) {
        logger.error(HttpStatus.METHOD_NOT_ALLOWED.getReasonPhrase(), e);
    }
    result.setSuccess(false);
    result.setMsg(e.getMessage());
    result.setResultCode(406);
    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 74 with ExceptionHandler

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

the class GlobalExceptionHandler method defaultExceptionHandler.

/**
 *	@ExceptionHandler(value = Exception.class)
 *	public void defaultExceptionHandler(HttpServletRequest request, Exception e){
 *		if (logger.isDebugEnabled()) {
 *			logger.error(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(), e);
 *		}
 *	}
 */
@ResponseBody
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ExceptionHandler(Exception.class)
public AjaxJson defaultExceptionHandler(final Exception 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) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 75 with ExceptionHandler

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

the class ExceptionControllerAdvice method handleUnauthorizedException.

@ExceptionHandler(APIException.class)
public ResponseEntity<String> handleUnauthorizedException(APIException exception) throws InvalidProtocolBufferException {
    Status.Builder statusBuilder = Status.newBuilder();
    statusBuilder.setCode(exception.getApiExceptionType().getId());
    statusBuilder.setReason(exception.getApiExceptionType().getMessage());
    statusBuilder.setInfo(exception.getInfo());
    statusBuilder.setStatus(Status.StatusFlag.FAILURE);
    Status status = statusBuilder.build();
    String json;
    json = ProtoBufUtils.toJson(status);
    return new ResponseEntity<String>(json, HttpStatus.valueOf(exception.getApiExceptionType().getHttpCode()));
}
Also used : HttpStatus(org.springframework.http.HttpStatus) Status(io.seldon.protos.PredictionProtos.Status) ResponseEntity(org.springframework.http.ResponseEntity) 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