Pārlūkot izejas kodu

未知异常响应状态码改为200

songxinlu 3 gadi atpakaļ
vecāks
revīzija
8f618117fc

+ 5 - 1
src/main/java/com/diagbot/config/AuthExceptionEntryPoint.java

@@ -1,5 +1,8 @@
 package com.diagbot.config;
 
+import com.diagbot.exception.CommonErrorCode;
+import com.diagbot.exception.CommonException;
+import com.diagbot.exception.ServiceErrorCode;
 import com.diagbot.util.StringUtil;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import org.springframework.security.core.AuthenticationException;
@@ -27,12 +30,13 @@ public class AuthExceptionEntryPoint implements AuthenticationEntryPoint {
         if (StringUtil.isNotEmpty(authException.getMessage())&&authException.getMessage().contains("Access token expired")) {
             map.put("code", "10020011");
             map.put("msg", "登录超时。为确保您的账户安全,系统已自动退出,请重新登录。");
+            response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
         }else {
+            response.setStatus(HttpServletResponse.SC_OK);
             map.put("code", "00000001");
             map.put("msg", authException.getMessage());
         }
         response.setContentType("application/json");
-        response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
         try {
             ObjectMapper mapper = new ObjectMapper();
             mapper.writeValue(response.getOutputStream(), map);