Explorar o código

来自 prometheus 的请求不携带 x-user-id header

reghao hai 1 ano
pai
achega
6acdb0ad8d

+ 4 - 0
content/content-service/src/main/java/cn/reghao/tnb/content/app/config/web/TokenFilter.java

@@ -22,6 +22,10 @@ public class TokenFilter implements Filter {
     public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
             throws IOException, ServletException {
         String userId = ServletUtil.getHeader("x-user-id");
+        if (userId == null) {
+            userId = "-1";
+        }
+
         String loginId = ServletUtil.getHeader("x-login-id");
         LoginUser loginUser = new LoginUser(Long.parseLong(userId));
         try (UserContext context = new UserContext(loginUser)) {