增强JWT拦截器异常处理
Some checks failed
Docker Build and Publish / build (push) Has been cancelled
Gitea Sync / trigger-gitea-sync (push) Has been cancelled
Java CI with Maven / build (push) Has been cancelled

新增异常处理,专门针对无法识别的token异常,提升错误提示的准确性。当token验证失败时,现在将抛出一个具体的"token验证失败,请重新登录"错误,以区别于登录过期错误。
This commit is contained in:
suyiiyii 2024-09-03 17:31:12 +08:00
parent 94bf792cd2
commit 28f5b146d8

View File

@ -48,6 +48,8 @@ public class JwtInterceptor implements HandlerInterceptor {
}
} catch (TokenExpiredException e) {
throw new ServiceException("401", "登录已过期,请重新登录");
} catch (Exception e) {
throw new ServiceException("401", "token验证失败请重新登录");
}
// 获取 token 中的 user id
Integer userId = Integer.parseInt(Objects.requireNonNull(JwtUtils.extractUserId(token)));