From 28f5b146d82930d5dd0b2fc7d4c0056b37fa48c8 Mon Sep 17 00:00:00 2001 From: suyiiyii Date: Tue, 3 Sep 2024 17:31:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=BC=BAJWT=E6=8B=A6=E6=88=AA?= =?UTF-8?q?=E5=99=A8=E5=BC=82=E5=B8=B8=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增异常处理,专门针对无法识别的token异常,提升错误提示的准确性。当token验证失败时,现在将抛出一个具体的"token验证失败,请重新登录"错误,以区别于登录过期错误。 --- src/main/java/top/suyiiyii/sims/common/JwtInterceptor.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/top/suyiiyii/sims/common/JwtInterceptor.java b/src/main/java/top/suyiiyii/sims/common/JwtInterceptor.java index 63b0254..10759c6 100644 --- a/src/main/java/top/suyiiyii/sims/common/JwtInterceptor.java +++ b/src/main/java/top/suyiiyii/sims/common/JwtInterceptor.java @@ -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)));