From 56b0c57cfd4489ad31019c21ff6886908ff6a91a Mon Sep 17 00:00:00 2001 From: guoyuji <guoyujie@ng.com> Date: 星期五, 26 四月 2024 14:03:12 +0800 Subject: [PATCH] 使用satoken进行登录 --- north-glass-erp/src/main/java/com/example/erp/exception/GlobalExceptionHandle.java | 18 ++++++++++++++++++ 1 files changed, 18 insertions(+), 0 deletions(-) diff --git a/north-glass-erp/src/main/java/com/example/erp/exception/GlobalExceptionHandle.java b/north-glass-erp/src/main/java/com/example/erp/exception/GlobalExceptionHandle.java index e353e73..b7227dc 100644 --- a/north-glass-erp/src/main/java/com/example/erp/exception/GlobalExceptionHandle.java +++ b/north-glass-erp/src/main/java/com/example/erp/exception/GlobalExceptionHandle.java @@ -1,5 +1,9 @@ package com.example.erp.exception; +import cn.dev33.satoken.exception.NotLoginException; +import cn.dev33.satoken.exception.NotPermissionException; +import cn.dev33.satoken.util.SaResult; +import com.example.erp.common.Constants; import com.example.erp.common.Result; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; @@ -15,4 +19,18 @@ public Result handle(ServiceException se){ return Result.error(se.getCode(),se.getMessage()); } + + @ExceptionHandler(NotPermissionException.class) + @ResponseBody + public Result handlerException(NotPermissionException e) { + return Result.error(Constants.Code_401,"This user has no permission to access this resource"); + } + + // 鎷︽埅锛氭湭鐧诲綍寮傚父 + @ExceptionHandler(NotLoginException.class) + @ResponseBody + public Result handlerException(NotLoginException e) { + // 杩斿洖缁欏墠绔� + return Result.error(Constants.Code_402,"Please login user"); + } } -- Gitblit v1.8.0