From 69e3afc7707d467b758858b52d3784947f7a502b Mon Sep 17 00:00:00 2001 From: 疯狂的狮子Li <15040126243@163.com> Date: 星期一, 20 五月 2024 10:25:23 +0800 Subject: [PATCH] !538 ♥️发布 5.2.0-BETA 公测版本 Merge pull request !538 from 疯狂的狮子Li/dev --- ruoyi-common/ruoyi-common-web/src/main/java/org/dromara/common/web/handler/GlobalExceptionHandler.java | 48 +++++++++++++----------------------------------- 1 files changed, 13 insertions(+), 35 deletions(-) diff --git a/ruoyi-common/ruoyi-common-security/src/main/java/org/dromara/common/security/handler/GlobalExceptionHandler.java b/ruoyi-common/ruoyi-common-web/src/main/java/org/dromara/common/web/handler/GlobalExceptionHandler.java similarity index 77% rename from ruoyi-common/ruoyi-common-security/src/main/java/org/dromara/common/security/handler/GlobalExceptionHandler.java rename to ruoyi-common/ruoyi-common-web/src/main/java/org/dromara/common/web/handler/GlobalExceptionHandler.java index a4dcfe3..bd47c18 100644 --- a/ruoyi-common/ruoyi-common-security/src/main/java/org/dromara/common/security/handler/GlobalExceptionHandler.java +++ b/ruoyi-common/ruoyi-common-web/src/main/java/org/dromara/common/web/handler/GlobalExceptionHandler.java @@ -1,8 +1,5 @@ -package org.dromara.common.security.handler; +package org.dromara.common.web.handler; -import cn.dev33.satoken.exception.NotLoginException; -import cn.dev33.satoken.exception.NotPermissionException; -import cn.dev33.satoken.exception.NotRoleException; import cn.hutool.core.util.ObjectUtil; import cn.hutool.http.HttpStatus; import jakarta.servlet.http.HttpServletRequest; @@ -21,6 +18,7 @@ import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; +import org.springframework.web.servlet.NoHandlerFoundException; /** * 鍏ㄥ眬寮傚父澶勭悊鍣� @@ -32,36 +30,6 @@ public class GlobalExceptionHandler { /** - * 鏉冮檺鐮佸紓甯� - */ - @ExceptionHandler(NotPermissionException.class) - public R<Void> handleNotPermissionException(NotPermissionException e, HttpServletRequest request) { - String requestURI = request.getRequestURI(); - log.error("璇锋眰鍦板潃'{}',鏉冮檺鐮佹牎楠屽け璐�'{}'", requestURI, e.getMessage()); - return R.fail(HttpStatus.HTTP_FORBIDDEN, "娌℃湁璁块棶鏉冮檺锛岃鑱旂郴绠$悊鍛樻巿鏉�"); - } - - /** - * 瑙掕壊鏉冮檺寮傚父 - */ - @ExceptionHandler(NotRoleException.class) - public R<Void> handleNotRoleException(NotRoleException e, HttpServletRequest request) { - String requestURI = request.getRequestURI(); - log.error("璇锋眰鍦板潃'{}',瑙掕壊鏉冮檺鏍¢獙澶辫触'{}'", requestURI, e.getMessage()); - return R.fail(HttpStatus.HTTP_FORBIDDEN, "娌℃湁璁块棶鏉冮檺锛岃鑱旂郴绠$悊鍛樻巿鏉�"); - } - - /** - * 璁よ瘉澶辫触 - */ - @ExceptionHandler(NotLoginException.class) - public R<Void> handleNotLoginException(NotLoginException e, HttpServletRequest request) { - String requestURI = request.getRequestURI(); - log.error("璇锋眰鍦板潃'{}',璁よ瘉澶辫触'{}',鏃犳硶璁块棶绯荤粺璧勬簮", requestURI, e.getMessage()); - return R.fail(HttpStatus.HTTP_UNAUTHORIZED, "璁よ瘉澶辫触锛屾棤娉曡闂郴缁熻祫婧�"); - } - - /** * 璇锋眰鏂瑰紡涓嶆敮鎸� */ @ExceptionHandler(HttpRequestMethodNotSupportedException.class) @@ -69,7 +37,7 @@ HttpServletRequest request) { String requestURI = request.getRequestURI(); log.error("璇锋眰鍦板潃'{}',涓嶆敮鎸�'{}'璇锋眰", requestURI, e.getMethod()); - return R.fail(e.getMessage()); + return R.fail(HttpStatus.HTTP_BAD_METHOD, e.getMessage()); } /** @@ -112,6 +80,16 @@ } /** + * 鎵句笉鍒拌矾鐢� + */ + @ExceptionHandler(NoHandlerFoundException.class) + public R<Void> handleNoHandlerFoundException(NoHandlerFoundException e, HttpServletRequest request) { + String requestURI = request.getRequestURI(); + log.error("璇锋眰鍦板潃'{}'涓嶅瓨鍦�.", requestURI); + return R.fail(HttpStatus.HTTP_NOT_FOUND, e.getMessage()); + } + + /** * 鎷︽埅鏈煡鐨勮繍琛屾椂寮傚父 */ @ExceptionHandler(RuntimeException.class) -- Gitblit v1.9.3