Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

路由拦截鉴权业务内部500错误也报错“未能读取到有效 token” #705

Open
caidingnu opened this issue Nov 14, 2024 · 2 comments

Comments

@caidingnu
Copy link

使用版本:

cn.dev33 sa-token-spring-boot-starter 1.39.0

涉及的功能模块:

cn.dev33 sa-token-spring-boot-starter 1.39.0

测试步骤:

  • 我经过以下步骤测试:

`package com.cdn.flex.config;

import cn.dev33.satoken.interceptor.SaInterceptor;
import cn.dev33.satoken.router.SaRouter;
import cn.dev33.satoken.stp.StpUtil;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**

  • 蔡定努

  • 2024/11/13 17:02
    */
    @configuration
    public class SaTokenConfigure implements WebMvcConfigurer {
    // 注册 Sa-Token 拦截器,打开注解式鉴权功能
    @OverRide
    public void addInterceptors(InterceptorRegistry registry) {
    registry.addInterceptor(new SaInterceptor(handle -> StpUtil.checkLogin()))
    .addPathPatterns("/**")
    .excludePathPatterns("/user/addMoney");
    }
    }

    @RequestMapping("addMoney")
    public SaResult addMoney() {

     if (1==1){
         throw new RuntimeException("test");
     }
    
     return SaResult.ok();
    

    }
    `

  • 得出以下结果:

此时应该报错RuntimeException,但是实际是NotLoginException,注解@SaCheckLogin 方式没问题

@LeeSmallNorth
Copy link

底层拦截了,可以全局异常处理

@ExceptionHandler(NotPermissionException.class)
public Result<Void> handleNotPermissionException(NotPermissionException e, HttpServletRequest request) {
    return Result.noAuth();
}

@ExceptionHandler(NotLoginException.class)
public Result<Void> handleNotLoginException(NotLoginException e, HttpServletRequest request) {
    return Result.noAuth();
}

@caidingnu
Copy link
Author

caidingnu commented Nov 21, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants