/**
* 全局的的异常拦截器
*
* @author cody
*/
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
/**
* IllegalArgumentException
*
* @param e the e
* @return the wrapper
*/
@ExceptionHandler(IllegalArgumentException.class)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public Wrapper illegalArgumentException(IllegalArgumentException e) {
log.error("IllegalArgumentException={}", e.getMessage(), e);
return WrapMapper.error("param error");
}
/**
* IllegalStateException
*
* @param e the e
* @return the wrapper
*/
@ExceptionHandler(IllegalStateException.class)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public Wrapper IllegalStateException(IllegalStateException e) {
log.error("IllegalStateException={}", e.getMessage(), e);
return WrapMapper.error();
}
/**
* HttpMessageNotWritableException
*
* @param e the e
* @return the wrapper
*/
@ExceptionHandler(HttpMessageNotWritableException.class)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public Wrapper HttpMessageNotWritableException(HttpMessageNotWritableException e) {
log.error("HttpMessageNotWritableException={}", e.getMessage(), e);
return WrapMapper.error();
}
/**
* HttpMessageNotReadableException
*
* @param e the e
* @return the wrapper
*/
@ExceptionHandler(HttpMessageNotReadableException.class)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public Wrapper HttpMessageNotReadableException(HttpMessageNotReadableException e) {
log.error("HttpMessageNotReadableException={}", e.getMessage(), e);
return WrapMapper.error();
}
}
SpringBoot异常处理
最新推荐文章于 2023-11-25 10:08:41 发布