Przeglądaj źródła

fix: Http.js 请求超时处理修复 — fial 拼写错误、res.data 空值保护

xiaohaizhao 1 tydzień temu
rodzic
commit
6d29d8d9ec
1 zmienionych plików z 11 dodań i 8 usunięć
  1. 11 8
      utils/Http.js

+ 11 - 8
utils/Http.js

@@ -149,21 +149,24 @@ class HTTP {
             header: header,
             timeout: 60000,
             success: res => resolve(res.data),
-            fial: err => reject(err),
+            fail: err => reject(err),
             complete: (res) => {
                 // if (loading) wx.hideLoading()
-                if (res.data.code != 1) {
-                    console.error("错误的请求", {
-                        request: data,
-                        result: res.data
-                    })
-                }
                 if (res.errMsg != 'request:ok') {
+                    console.error("请求失败", { request: data, result: res })
                     wx.showToast({
                         title: getApp().globalData.Language.getMapText('网络异常,请重新进入'),
                         icon: "none"
                     })
-                } else if (res.data.msg == '登陆状态已过期,请重新登陆!' || res.data.msg == getApp().globalData.Language.getMapText('登陆状态已过期,请重新登陆!')) {
+                    return
+                }
+                if (res.data && res.data.code != 1) {
+                    console.error("错误的请求", {
+                        request: data,
+                        result: res.data
+                    })
+                }
+                if (res.data && (res.data.msg == '登陆状态已过期,请重新登陆!' || res.data.msg == getApp().globalData.Language.getMapText('登陆状态已过期,请重新登陆!'))) {
                     wx.showToast({
                         title: getApp().globalData.Language.getMapText(res.data.msg),
                         icon: "none",