|
@@ -7,8 +7,10 @@ import org.springframework.security.access.AccessDeniedException; |
|
@@ -7,8 +7,10 @@ import org.springframework.security.access.AccessDeniedException; |
|
7
|
import org.springframework.validation.BindException;
|
7
|
import org.springframework.validation.BindException;
|
|
8
|
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
8
|
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
|
9
|
import org.springframework.web.bind.MethodArgumentNotValidException;
|
9
|
import org.springframework.web.bind.MethodArgumentNotValidException;
|
|
|
|
10
|
+import org.springframework.web.bind.MissingPathVariableException;
|
|
10
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
11
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
11
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
12
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
|
|
|
13
|
+import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
|
|
12
|
import com.ruoyi.common.constant.HttpStatus;
|
14
|
import com.ruoyi.common.constant.HttpStatus;
|
|
13
|
import com.ruoyi.common.core.domain.AjaxResult;
|
15
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
14
|
import com.ruoyi.common.exception.DemoModeException;
|
16
|
import com.ruoyi.common.exception.DemoModeException;
|
|
@@ -60,6 +62,28 @@ public class GlobalExceptionHandler |
|
@@ -60,6 +62,28 @@ public class GlobalExceptionHandler |
|
60
|
}
|
62
|
}
|
|
61
|
|
63
|
|
|
62
|
/**
|
64
|
/**
|
|
|
|
65
|
+ * 请求路径中缺少必需的路径变量
|
|
|
|
66
|
+ */
|
|
|
|
67
|
+ @ExceptionHandler(MissingPathVariableException.class)
|
|
|
|
68
|
+ public AjaxResult handleMissingPathVariableException(MissingPathVariableException e, HttpServletRequest request)
|
|
|
|
69
|
+ {
|
|
|
|
70
|
+ String requestURI = request.getRequestURI();
|
|
|
|
71
|
+ log.error("请求路径中缺少必需的路径变量'{}',发生系统异常.", requestURI, e);
|
|
|
|
72
|
+ return AjaxResult.error(String.format("请求路径中缺少必需的路径变量[%s]", e.getVariableName()));
|
|
|
|
73
|
+ }
|
|
|
|
74
|
+
|
|
|
|
75
|
+ /**
|
|
|
|
76
|
+ * 请求参数类型不匹配
|
|
|
|
77
|
+ */
|
|
|
|
78
|
+ @ExceptionHandler(MethodArgumentTypeMismatchException.class)
|
|
|
|
79
|
+ public AjaxResult handleMethodArgumentTypeMismatchException(MethodArgumentTypeMismatchException e, HttpServletRequest request)
|
|
|
|
80
|
+ {
|
|
|
|
81
|
+ String requestURI = request.getRequestURI();
|
|
|
|
82
|
+ log.error("请求参数类型不匹配'{}',发生系统异常.", requestURI, e);
|
|
|
|
83
|
+ return AjaxResult.error(String.format("请求参数类型不匹配,参数[%s]要求类型为:'%s',但输入值为:'%s'", e.getName(), e.getRequiredType().getName(), e.getValue()));
|
|
|
|
84
|
+ }
|
|
|
|
85
|
+
|
|
|
|
86
|
+ /**
|
|
63
|
* 拦截未知的运行时异常
|
87
|
* 拦截未知的运行时异常
|
|
64
|
*/
|
88
|
*/
|
|
65
|
@ExceptionHandler(RuntimeException.class)
|
89
|
@ExceptionHandler(RuntimeException.class)
|