Browse Source

优化client错误判断

zhouhao 7 years ago
parent
commit
bf39fe8445

+ 16 - 11
hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-client/src/main/java/org/hswebframework/web/authorization/oauth2/client/simple/provider/HswebResponseJudgeSupport.java

@@ -44,19 +44,24 @@ public class HswebResponseJudgeSupport implements ResponseJudgeForProviderDefini
         if (!result.trim().startsWith("{")) {
         if (!result.trim().startsWith("{")) {
             return null;
             return null;
         }
         }
-        JSONObject jsonRes = JSON.parseObject(result);
-        Integer status = jsonRes.getInteger("status");
-        if (status == null && response.status() == 200) {
-            return null;
-        }
-        if (status != null) {
-            if (status == 200) {
+        try {
+            JSONObject jsonRes = JSON.parseObject(result);
+            if (jsonRes.size() > 5) return null;
+            Integer status = jsonRes.getInteger("status");
+            if (status == null && response.status() == 200) {
                 return null;
                 return null;
             }
             }
-            return ErrorType.fromCode(status).orElse(ErrorType.OTHER);
-        }
-        if (jsonRes.get("message") != null) {
-            return ErrorType.valueOf(jsonRes.getString("message"));
+            if (status != null) {
+                if (status == 200) {
+                    return null;
+                }
+                return ErrorType.fromCode(status).orElse(ErrorType.OTHER);
+            }
+            if (jsonRes.get("message") != null) {
+                return ErrorType.valueOf(jsonRes.getString("message"));
+            }
+        } catch (Exception ignore) {
+
         }
         }
         return null;
         return null;
     }
     }