From 2782c369c9317c916b4b63ea9589c8588ce7ed7f Mon Sep 17 00:00:00 2001 From: 疯狂的狮子Li <15040126243@163.com> Date: 星期二, 30 四月 2024 16:25:51 +0800 Subject: [PATCH] update 优化 常规web异常状态码 --- ruoyi-common/ruoyi-common-security/src/main/java/org/dromara/common/security/handler/GlobalExceptionHandler.java | 13 ++++++++++++- 1 files changed, 12 insertions(+), 1 deletions(-) diff --git a/ruoyi-common/ruoyi-common-security/src/main/java/org/dromara/common/security/handler/GlobalExceptionHandler.java b/ruoyi-common/ruoyi-common-security/src/main/java/org/dromara/common/security/handler/GlobalExceptionHandler.java index a4dcfe3..f2e573f 100644 --- a/ruoyi-common/ruoyi-common-security/src/main/java/org/dromara/common/security/handler/GlobalExceptionHandler.java +++ b/ruoyi-common/ruoyi-common-security/src/main/java/org/dromara/common/security/handler/GlobalExceptionHandler.java @@ -21,6 +21,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; /** * 鍏ㄥ眬寮傚父澶勭悊鍣� @@ -69,7 +70,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 +113,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