Jelajahi Sumber

Merge branch 'master' of https://matrix.niimei.com/szustar/szugift-fe

StephenArk30 6 tahun lalu
induk
melakukan
1c88c4f5a1
1 mengubah file dengan 22 tambahan dan 25 penghapusan
  1. 22 25
      sourcecode/h5app/vue/src/connector/basic-service.js

+ 22 - 25
sourcecode/h5app/vue/src/connector/basic-service.js

@@ -199,7 +199,8 @@ var BasicFunction = new (function () {
             sendTime: new Date()
         }).then(BasicFunction.checkStatus)
           .then(BasicFunction.parseJson)
-          .then(BasicFunction.on_dat_success)
+          .then(function(response){return response.json()})
+          .then(callback)
           .catch(BasicFunction.on_fail);
     }
 
@@ -210,40 +211,36 @@ var BasicFunction = new (function () {
             sendTime: new Date(),
             gid: gid,
             callme: callback
-        }).then(res => {
-            return res.json()
-        })
-            .then(BasicFunction.on_gp_success)
+        }).then(BasicFunction.checkStatus)
+        .then(BasicFunction.parseJson)
+        .then(function(response){return response.json()})
+        .then(BasicFunction.onReqeustDataReceived)
         .then(callback)
         .catch(BasicFunction.on_fail);
     }
 
     this.on_gp_success = function(response) {
         var obj = response.json();
-        var b = respose.status;
-        var gid = obj.gid;
-        if (BasicFunction.check_if_success(obj, b)) {
-            obj.callme(obj, b);
-            BasicFunction.Queue.groups.forEach(function (v) {
-                if (v.gid === gid) {
-                    v.counter++;
-                    return v;
-                }
-            });
-        }
-        return null;
+        return obj;
     };
 
-    this.on_dat_success = function(responseJson) {
+    this.onReqeustDataReceived = function(responseJson) {
+        console.warn(responseJson);
         var a = responseJson;
-        // if (BasicFunction.check_if_authfail(a, {})) {
+        if (!BasicFunction.check_if_authfail(a)) {
+            const error = new Error(responseJson.statusText);
+            error.response = responseJson;
+            throw error;
+        }
+        if (!BasicFunction.check_if_success(a)) {
+            const error = new Error(responseJson.statusText);
+            error.response = responseJson;
+            throw error;
+        }
+        return responseJson;
         //     BasicFunction.setCookieWithTimeout("doibyUser", "", -10);
         //     location.href = "sign-in1.html?from=entrance-5&msg=server-redirect-detected";
         //     return;
-        // }
-        //BasicFunction.check_if_success(a, {})) {
-        return a;
-        //}
     };
 
     this.check_if_authfail = function (errormsg) {
@@ -295,7 +292,7 @@ var BasicFunction = new (function () {
         return false;
     };
 
-    this.on_fail = function (msg, sta, obj) {
+    this.on_fail = function (msg) {
         BasicFunction.Queue.errorCount += 1;
         if (BasicFunction.Queue.errorCount >= 10) {
             BasicFunction.Queue.errorCount = 0;
@@ -304,7 +301,7 @@ var BasicFunction = new (function () {
             BasicFunction.logwarn("-----  Too many failure, temporary stop HTTP ------");
             BasicFunction.send_alert("很抱歉,网络错误数量过多,暂时终止HTTP功能30s");
         }
-        BasicFunction.send_alert("很抱歉,网络错误,请查看 Console");
+        BasicFunction.send_alert(" 很抱歉,网络错误,请查看 Console");
         BasicFunction.logwarn("-----   网络请求失败 ---------");
         BasicFunction.logwarn("-----------msg-------------");
         BasicFunction.logwarn(JSON.stringify(msg));