guoyujie
3 天以前 c4b9a339caff12e95f61c3d5dc950aafcc8c566c
north-glass-erp/src/main/java/com/example/erp/exception/GlobalExceptionHandle.java
@@ -1,9 +1,15 @@
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;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.Arrays;
@ControllerAdvice
public class GlobalExceptionHandle {
@@ -15,4 +21,19 @@
    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,e.getPermission());
    }
    // 拦截:未登录异常
    @ExceptionHandler(NotLoginException.class)
    @ResponseBody
    public Result handlerException(NotLoginException e) {
        // 返回给前端
        return Result.error(Constants.Code_402,"Please login user");
    }
}