From d153ca8d05991566bed18eed1ae25f0af3c1cc70 Mon Sep 17 00:00:00 2001
From: Pu Zhibing <393733352@qq.com>
Date: 星期五, 27 九月 2024 10:40:06 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'
---
ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/handler/GlobalExceptionHandler.java | 251 ++++++++++++++++++++++++--------------------------
1 files changed, 120 insertions(+), 131 deletions(-)
diff --git a/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/handler/GlobalExceptionHandler.java b/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/handler/GlobalExceptionHandler.java
index 262a05f..1da5038 100644
--- a/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/handler/GlobalExceptionHandler.java
+++ b/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/handler/GlobalExceptionHandler.java
@@ -27,138 +27,127 @@
/**
* 全局异常处理器
- *
+ *
* @author ruoyi
*/
@RestControllerAdvice
-public class GlobalExceptionHandler
-{
- private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);
-
- @Value("${spring.servlet.multipart.max-file-size:4MB}")
- private String maxFileSize;
- @Value("${spring.servlet.multipart.max-request-size:100MB}")
- private String maxRequestSize;
-
-
- /**
- * 权限码异常
- */
- @ExceptionHandler(NotPermissionException.class)
- public AjaxResult handleNotPermissionException(NotPermissionException e, HttpServletRequest request)
- {
- String requestURI = request.getRequestURI();
- log.error("请求地址'{}',权限码校验失败'{}'", requestURI, e.getMessage());
- return AjaxResult.error(HttpStatus.FORBIDDEN, "没有访问权限,请联系管理员授权");
- }
-
- /**
- * 角色权限异常
- */
- @ExceptionHandler(NotRoleException.class)
- public AjaxResult handleNotRoleException(NotRoleException e, HttpServletRequest request)
- {
- String requestURI = request.getRequestURI();
- log.error("请求地址'{}',角色权限校验失败'{}'", requestURI, e.getMessage());
- return AjaxResult.error(HttpStatus.FORBIDDEN, "没有访问权限,请联系管理员授权");
- }
-
- /**
- * 请求方式不支持
- */
- @ExceptionHandler(HttpRequestMethodNotSupportedException.class)
- public AjaxResult handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException e,
- HttpServletRequest request)
- {
- String requestURI = request.getRequestURI();
- log.error("请求地址'{}',不支持'{}'请求", requestURI, e.getMethod());
- return AjaxResult.error(e.getMessage());
- }
-
- /**
- * 业务异常
- */
- @ExceptionHandler(ServiceException.class)
- public AjaxResult handleServiceException(ServiceException e, HttpServletRequest request)
- {
- log.error(e.getMessage(), e);
- Integer code = e.getCode();
- return StringUtils.isNotNull(code) ? AjaxResult.error(code, e.getMessage()) : AjaxResult.error(e.getMessage());
- }
-
- /**
- * 拦截未知的运行时异常
- */
- @ExceptionHandler(RuntimeException.class)
- public AjaxResult handleRuntimeException(RuntimeException e, HttpServletRequest request)
- {
- String requestURI = request.getRequestURI();
- log.error("请求地址'{}',发生未知异常.", requestURI, e);
- return AjaxResult.error(e.getMessage());
- }
-
- /**
- * 系统异常
- */
- @ExceptionHandler(Exception.class)
- public AjaxResult handleException(Exception e, HttpServletRequest request)
- {
- String requestURI = request.getRequestURI();
- log.error("请求地址'{}',发生系统异常.", requestURI, e);
- return AjaxResult.error(e.getMessage());
- }
-
- /**
- * 自定义验证异常
- */
- @ExceptionHandler(BindException.class)
- public AjaxResult handleBindException(BindException e)
- {
- log.error(e.getMessage(), e);
- String message = e.getAllErrors().get(0).getDefaultMessage();
- return AjaxResult.error(message);
- }
-
- /**
- * 自定义验证异常
- */
- @ExceptionHandler(MethodArgumentNotValidException.class)
- public Object handleMethodArgumentNotValidException(MethodArgumentNotValidException e)
- {
- log.error(e.getMessage(), e);
- String message = e.getBindingResult().getFieldError().getDefaultMessage();
- return AjaxResult.error(message);
- }
-
- /**
- * 内部认证异常
- */
- @ExceptionHandler(InnerAuthException.class)
- public AjaxResult handleInnerAuthException(InnerAuthException e)
- {
- return AjaxResult.error(e.getMessage());
- }
-
- /**
- * 演示模式异常
- */
- @ExceptionHandler(DemoModeException.class)
- public AjaxResult handleDemoModeException(DemoModeException e)
- {
- return AjaxResult.error("演示模式,不允许操作");
- }
-
- @ExceptionHandler(MaxUploadSizeExceededException.class)
- public AjaxResult fileUpLoad(MaxUploadSizeExceededException e) {
- log.error("上传文件异常 => : {}", e.getMessage());
- return AjaxResult.error("文件识别大小超出限制,允许的大小在" + maxFileSize);
- }
-
- /**
- * 学生端单点登录-异常信息
- */
- @ExceptionHandler(UserAppletException.class)
- public AjaxResult<String> studyLoginExceptionHandler(UserAppletException e) {
- return AjaxResult.error(e.getCode(), e.getMessage());
- }
+public class GlobalExceptionHandler {
+ private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);
+
+ @Value("${spring.servlet.multipart.max-file-size}")
+ private String maxFileSize;
+ @Value("${spring.servlet.multipart.max-request-size}")
+ private String maxRequestSize;
+
+
+ /**
+ * 权限码异常
+ */
+ @ExceptionHandler(NotPermissionException.class)
+ public AjaxResult handleNotPermissionException(NotPermissionException e, HttpServletRequest request) {
+ String requestURI = request.getRequestURI();
+ log.error("请求地址'{}',权限码校验失败'{}'", requestURI, e.getMessage());
+ return AjaxResult.error(HttpStatus.FORBIDDEN, "没有访问权限,请联系管理员授权");
+ }
+
+ /**
+ * 角色权限异常
+ */
+ @ExceptionHandler(NotRoleException.class)
+ public AjaxResult handleNotRoleException(NotRoleException e, HttpServletRequest request) {
+ String requestURI = request.getRequestURI();
+ log.error("请求地址'{}',角色权限校验失败'{}'", requestURI, e.getMessage());
+ return AjaxResult.error(HttpStatus.FORBIDDEN, "没有访问权限,请联系管理员授权");
+ }
+
+ /**
+ * 请求方式不支持
+ */
+ @ExceptionHandler(HttpRequestMethodNotSupportedException.class)
+ public AjaxResult handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException e,
+ HttpServletRequest request) {
+ String requestURI = request.getRequestURI();
+ log.error("请求地址'{}',不支持'{}'请求", requestURI, e.getMethod());
+ return AjaxResult.error(e.getMessage());
+ }
+
+ /**
+ * 业务异常
+ */
+ @ExceptionHandler(ServiceException.class)
+ public AjaxResult handleServiceException(ServiceException e, HttpServletRequest request) {
+ log.error(e.getMessage(), e);
+ Integer code = e.getCode();
+ return StringUtils.isNotNull(code) ? AjaxResult.error(code, e.getMessage()) : AjaxResult.error(e.getMessage());
+ }
+
+ /**
+ * 拦截未知的运行时异常
+ */
+ @ExceptionHandler(RuntimeException.class)
+ public AjaxResult handleRuntimeException(RuntimeException e, HttpServletRequest request) {
+ String requestURI = request.getRequestURI();
+ log.error("请求地址'{}',发生未知异常.", requestURI, e);
+ return AjaxResult.error(e.getMessage());
+ }
+
+ /**
+ * 系统异常
+ */
+ @ExceptionHandler(Exception.class)
+ public AjaxResult handleException(Exception e, HttpServletRequest request) {
+ String requestURI = request.getRequestURI();
+ log.error("请求地址'{}',发生系统异常.", requestURI, e);
+ return AjaxResult.error(e.getMessage());
+ }
+
+ /**
+ * 自定义验证异常
+ */
+ @ExceptionHandler(BindException.class)
+ public AjaxResult handleBindException(BindException e) {
+ log.error(e.getMessage(), e);
+ String message = e.getAllErrors().get(0).getDefaultMessage();
+ return AjaxResult.error(message);
+ }
+
+ /**
+ * 自定义验证异常
+ */
+ @ExceptionHandler(MethodArgumentNotValidException.class)
+ public Object handleMethodArgumentNotValidException(MethodArgumentNotValidException e) {
+ log.error(e.getMessage(), e);
+ String message = e.getBindingResult().getFieldError().getDefaultMessage();
+ return AjaxResult.error(message);
+ }
+
+ /**
+ * 内部认证异常
+ */
+ @ExceptionHandler(InnerAuthException.class)
+ public AjaxResult handleInnerAuthException(InnerAuthException e) {
+ return AjaxResult.error(e.getMessage());
+ }
+
+ /**
+ * 演示模式异常
+ */
+ @ExceptionHandler(DemoModeException.class)
+ public AjaxResult handleDemoModeException(DemoModeException e) {
+ return AjaxResult.error("演示模式,不允许操作");
+ }
+
+ @ExceptionHandler(MaxUploadSizeExceededException.class)
+ public AjaxResult fileUpLoad(MaxUploadSizeExceededException e) {
+ log.error("上传文件异常 => : {}", e.getMessage());
+ return AjaxResult.error("文件识别大小超出限制,允许的大小在" + maxFileSize);
+ }
+
+ /**
+ * 学生端单点登录-异常信息
+ */
+ @ExceptionHandler(UserAppletException.class)
+ public AjaxResult<String> studyLoginExceptionHandler(UserAppletException e) {
+ return AjaxResult.error(e.getCode(), e.getMessage());
+ }
}
--
Gitblit v1.7.1