guoyuji
2024-04-26 684399b665ef8c25c43faff0fdc821a0b72b39ba
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");
    }
}