Эх сурвалжийг харах

统计后台api请求错误率

Michael Wang 5 жил өмнө
parent
commit
de2f8a6038
1 өөрчлөгдсөн 24 нэмэгдсэн , 0 устгасан
  1. 24 0
      src/utils/axios.js

+ 24 - 0
src/utils/axios.js

@@ -72,6 +72,12 @@ qmInstance.interceptors.response.use(
         window.___lastNetworkError = Date.now();
       }
 
+      window._hmt.push([
+        "_trackEvent",
+        location.pathname,
+        "网络连接异常,请检查网络设置。",
+      ]);
+
       return Promise.reject(error);
     }
     // 这里是返回状态码不为200时候的错误处理
@@ -107,6 +113,12 @@ qmInstance.interceptors.response.use(
       // router.push("/login/" + localStorage.getItem("domain"));
       return; // 仅显示登录失效,不显示因登录失效造成的后续错误
     } else if (status == 502) {
+      window._hmt.push([
+        "_trackEvent",
+        location.pathname,
+        "服务器异常(502)!",
+        error.config.url,
+      ]);
       Message.error({
         content: "服务器异常(502)!",
         duration: 15,
@@ -114,6 +126,12 @@ qmInstance.interceptors.response.use(
       });
       return;
     } else if (status == 503) {
+      window._hmt.push([
+        "_trackEvent",
+        location.pathname,
+        "服务器繁忙(503)!请稍后重试。",
+        error.config.url,
+      ]);
       Message.error({
         content: "服务器繁忙(503)!请稍后重试。",
         duration: 15,
@@ -121,6 +139,12 @@ qmInstance.interceptors.response.use(
       });
       return;
     } else if (status != 200) {
+      window._hmt.push([
+        "_trackEvent",
+        location.pathname,
+        "status: " + status,
+        error.config.url,
+      ]);
       if (
         wk_token &&
         ![401, 403].includes(status) &&