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;
}
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;
}
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;
}
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;
}
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()));
}
Aggregations