Browse Source

权限不足异常拦截

caixiaofeng 11 tháng trước cách đây
mục cha
commit
d039cdfe61

+ 8 - 0
flow-common/flow-common-core/src/main/java/com/flow/common/core/exception/handler/BaseExceptionHandler.java

@@ -6,6 +6,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.core.Ordered;
 import org.springframework.core.annotation.Order;
 import org.springframework.http.HttpStatus;
+import org.springframework.security.access.AccessDeniedException;
 import org.springframework.web.HttpMediaTypeNotSupportedException;
 import org.springframework.web.HttpRequestMethodNotSupportedException;
 import org.springframework.web.bind.MethodArgumentNotValidException;
@@ -72,6 +73,13 @@ public class BaseExceptionHandler {
         return Result.error(e.getMessage());
     }
 
+    @ExceptionHandler(AccessDeniedException.class)
+    @ResponseStatus(HttpStatus.BAD_REQUEST)
+    public Result accessDeniedException(AccessDeniedException e){
+        e.printStackTrace();
+        return Result.error(e.getMessage());
+    }
+
 
     /**
      * 参数异常拦截