Ver Fonte

fix: 修复401、403请求日志不打印响应内容

weijianghai há 2 anos atrás
pai
commit
4406a5b5a7

+ 4 - 4
src/main/java/com/nokia/config/web/WebLoginInterceptor.java

@@ -29,16 +29,16 @@ public class WebLoginInterceptor implements HandlerInterceptor {
         if (session == null || session.getAttribute("userinfo") == null) {
             response.setCharacterEncoding("UTF-8");
             response.setContentType("application/json; charset=utf-8");
-            response.getWriter().write(JSON.toJSONString(R.error().code(401).message("登录失效")));
-            log.warn("登录失效");
+            byte[] bytes = JSON.toJSONString(R.error().code(401).message("登录失效")).getBytes();
+            response.getOutputStream().write(bytes);
             return false;
         }
         // 没有权限返回403
         if (session.getAttribute("role") == null) {
             response.setCharacterEncoding("UTF-8");
             response.setContentType("application/json; charset=utf-8");
-            response.getWriter().write(JSON.toJSONString(R.error().code(403).message("权限不足")));
-            log.warn("权限不足");
+            byte[] bytes = JSON.toJSONString(R.error().code(403).message("权限不足")).getBytes();
+            response.getOutputStream().write(bytes);
             return false;
         }
         log.debug("sessionId: {}, userinfo: {}, role: {}", session.getId(),