From a4caa73d061fb369b2b395a2f2290a9dc40d7a28 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=9C=89=E6=9D=A5=E6=8A=80=E6=9C=AF?= <1490493387@qq.com>
Date: Tue, 17 Aug 2021 01:08:53 +0800
Subject: [PATCH] =?UTF-8?q?feat(GlobalExceptionHandler.java):=20=E6=B7=BB?=
=?UTF-8?q?=E5=8A=A0=E7=AE=A1=E7=90=86=E7=AB=AF=E5=92=8C=E5=B0=8F=E7=A8=8B?=
=?UTF-8?q?=E5=BA=8F=E7=AB=AF=E7=9A=84HttpStatus=E5=A4=84=E7=90=86?=
=?UTF-8?q?=EF=BC=8C=E8=A7=A3=E5=BC=80=E6=B3=A8=E9=87=8A=E8=B0=83=E6=95=B4?=
=?UTF-8?q?=E5=BC=82=E5=B8=B8=E5=A4=84=E7=90=86=E7=9A=84HTTP=E7=8A=B6?=
=?UTF-8?q?=E6=80=81=E7=A0=81=EF=BC=8C=E4=B8=B0=E5=AF=8C=E5=BC=82=E5=B8=B8?=
=?UTF-8?q?=E5=A4=84=E7=90=86=E7=B1=BB=E5=9E=8B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Closes #57
---
.../web/exception/GlobalExceptionHandler.java | 29 ++++++++++---------
1 file changed, 16 insertions(+), 13 deletions(-)
diff --git a/youlai-common/common-web/src/main/java/com/youlai/common/web/exception/GlobalExceptionHandler.java b/youlai-common/common-web/src/main/java/com/youlai/common/web/exception/GlobalExceptionHandler.java
index 102ab9736..a21676b34 100644
--- a/youlai-common/common-web/src/main/java/com/youlai/common/web/exception/GlobalExceptionHandler.java
+++ b/youlai-common/common-web/src/main/java/com/youlai/common/web/exception/GlobalExceptionHandler.java
@@ -26,9 +26,12 @@ import java.util.regex.Pattern;
/**
* 全局系统异常处理
+ * 调整异常处理的HTTP状态码,丰富异常处理类型
*
* @author hxrui
+ * @author Gadfly
* @date 2020-02-25 13:54
+ *
**/
@RestControllerAdvice
@Slf4j
@@ -36,7 +39,7 @@ public class GlobalExceptionHandler {
/**
* 表单绑定到 java bean 出错时抛出 BindException 异常
*/
- // @ResponseStatus(HttpStatus.BAD_REQUEST)
+ @ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(BindException.class)
public Result processException(BindException e) {
log.error(e.getMessage(), e);
@@ -57,7 +60,7 @@ public class GlobalExceptionHandler {
/**
* 普通参数(非 java bean)校验出错时抛出 ConstraintViolationException 异常
*/
- // @ResponseStatus(HttpStatus.BAD_REQUEST)
+ @ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(ConstraintViolationException.class)
public Result processException(ConstraintViolationException e) {
log.error(e.getMessage(), e);
@@ -70,7 +73,7 @@ public class GlobalExceptionHandler {
return Result.failed(ResultCode.PARAM_ERROR, msg.toString());
}
- // @ResponseStatus(HttpStatus.BAD_REQUEST)
+ @ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(ValidationException.class)
public Result processException(ValidationException e) {
log.error(e.getMessage(), e);
@@ -90,7 +93,7 @@ public class GlobalExceptionHandler {
/**
* MissingServletRequestParameterException
*/
- // @ResponseStatus(HttpStatus.BAD_REQUEST)
+ @ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(MissingServletRequestParameterException.class)
public Result processException(MissingServletRequestParameterException e) {
log.error(e.getMessage(), e);
@@ -100,7 +103,7 @@ public class GlobalExceptionHandler {
/**
* MethodArgumentTypeMismatchException
*/
- // @ResponseStatus(HttpStatus.BAD_REQUEST)
+ @ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(MethodArgumentTypeMismatchException.class)
public Result processException(MethodArgumentTypeMismatchException e) {
log.error(e.getMessage(), e);
@@ -110,21 +113,21 @@ public class GlobalExceptionHandler {
/**
* ServletException
*/
- // @ResponseStatus(HttpStatus.BAD_REQUEST)
+ @ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(ServletException.class)
public Result processException(ServletException e) {
log.error(e.getMessage(), e);
return Result.failed(e.getMessage());
}
- // @ResponseStatus(HttpStatus.BAD_REQUEST)
+ @ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(IllegalArgumentException.class)
public Result handleIllegalArgumentException(IllegalArgumentException e) {
log.error("非法参数异常,异常原因:{}", e.getMessage(), e);
return Result.failed(e.getMessage());
}
- // @ResponseStatus(HttpStatus.BAD_REQUEST)
+ @ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(JsonProcessingException.class)
public Result handleJsonProcessingException(JsonProcessingException e) {
log.error("Json转换异常,异常原因:{}", e.getMessage(), e);
@@ -134,7 +137,7 @@ public class GlobalExceptionHandler {
/**
* HttpMessageNotReadableException
*/
- // @ResponseStatus(HttpStatus.BAD_REQUEST)
+ @ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(HttpMessageNotReadableException.class)
public Result processException(HttpMessageNotReadableException e) {
log.error(e.getMessage(), e);
@@ -149,7 +152,7 @@ public class GlobalExceptionHandler {
/**
* TypeMismatchException
*/
- // @ResponseStatus(HttpStatus.BAD_REQUEST)
+ @ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(TypeMismatchException.class)
public Result processException(TypeMismatchException e) {
log.error(e.getMessage(), e);
@@ -159,7 +162,7 @@ public class GlobalExceptionHandler {
/**
* CompletionException
*/
- // @ResponseStatus(HttpStatus.BAD_REQUEST)
+ @ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(CompletionException.class)
public Result processException(CompletionException e) {
log.error(e.getMessage(), e);
@@ -169,7 +172,7 @@ public class GlobalExceptionHandler {
return handleException(e);
}
- // @ResponseStatus(HttpStatus.BAD_REQUEST)
+ @ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(BizException.class)
public Result handleBizException(BizException e) {
log.error("业务异常,异常原因:{}", e.getMessage(), e);
@@ -179,7 +182,7 @@ public class GlobalExceptionHandler {
return Result.failed(e.getMessage());
}
- // @ResponseStatus(HttpStatus.BAD_REQUEST)
+ @ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(Exception.class)
public Result handleException(Exception e) {
log.error("未知异常,异常原因:{}", e.getMessage(), e);