From 695cb6d76b838b1e4cb161bae335faa948dca12a Mon Sep 17 00:00:00 2001 From: 疯狂的狮子li <15040126243@163.com> Date: 星期三, 27 十月 2021 13:16:19 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/dev' into satoken --- ruoyi-framework/src/main/java/com/ruoyi/framework/web/exception/GlobalExceptionHandler.java | 29 +++++++++++++++++++++++++++-- 1 files changed, 27 insertions(+), 2 deletions(-) diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/exception/GlobalExceptionHandler.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/exception/GlobalExceptionHandler.java index d76e616..6cf5e40 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/exception/GlobalExceptionHandler.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/exception/GlobalExceptionHandler.java @@ -1,5 +1,8 @@ package com.ruoyi.framework.web.exception; +import cn.dev33.satoken.exception.NotLoginException; +import cn.dev33.satoken.exception.NotPermissionException; +import cn.dev33.satoken.exception.NotRoleException; import cn.hutool.http.HttpStatus; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.exception.DemoModeException; @@ -28,14 +31,36 @@ /** * 鏉冮檺鏍¢獙寮傚父 */ - @ExceptionHandler(AccessDeniedException.class) - public AjaxResult<Void> handleAccessDeniedException(AccessDeniedException e, HttpServletRequest request) { + @ExceptionHandler(NotPermissionException.class) + public AjaxResult<Void> handleAccessDeniedException(NotPermissionException e, HttpServletRequest request) { String requestURI = request.getRequestURI(); log.error("璇锋眰鍦板潃'{}',鏉冮檺鏍¢獙澶辫触'{}'", requestURI, e.getMessage()); return AjaxResult.error(HttpStatus.HTTP_FORBIDDEN, "娌℃湁鏉冮檺锛岃鑱旂郴绠$悊鍛樻巿鏉�"); } /** + * 瑙掕壊鏍¢獙寮傚父 + */ + @ExceptionHandler(NotRoleException.class) + public AjaxResult handleAccessDeniedException(NotRoleException e, HttpServletRequest request) + { + String requestURI = request.getRequestURI(); + log.error("璇锋眰鍦板潃'{}',瑙掕壊鏍¢獙澶辫触'{}'", requestURI, e.getMessage()); + return AjaxResult.error(HttpStatus.HTTP_FORBIDDEN, "娌℃湁瑙掕壊锛岃鑱旂郴绠$悊鍛樻巿鏉�"); + } + + /** + * 璁よ瘉澶辫触 + */ + @ExceptionHandler(NotLoginException.class) + public AjaxResult handleAccessDeniedException(NotLoginException e, HttpServletRequest request) + { + String requestURI = request.getRequestURI(); + log.error("璇锋眰璁块棶锛歿}锛岃璇佸け璐ワ紝鏃犳硶璁块棶绯荤粺璧勬簮", requestURI, e.getMessage()); + return AjaxResult.error(HttpStatus.HTTP_UNAUTHORIZED, StringUtils.format("璇锋眰璁块棶锛歿}锛岃璇佸け璐ワ紝鏃犳硶璁块棶绯荤粺璧勬簮", requestURI)); + } + + /** * 璇锋眰鏂瑰紡涓嶆敮鎸� */ @ExceptionHandler(HttpRequestMethodNotSupportedException.class) -- Gitblit v1.9.3