JEECG&JWT異常捕獲強化處理 | Java: Meaning of catch (final SomeException e)?
阿新 • • 發佈:2018-12-01
//從header中得到token String authHeader = request.getHeader(JwtConstants.AUTHORIZATION); if (authHeader == null) { throw new ServletException("Missing or invalid X-AUTH-TOKEN header."); } // 驗證token Claims claims = null; try { claims= Jwts.parser().setSigningKey(JwtConstants.JWT_SECRET).parseClaimsJws(authHeader).getBody(); } catch (final MalformedJwtException e){ throw new ServletException("token 長度或者格式錯誤."); } catch (final SignatureException e) { throw new ServletException("Invalid token."); }