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

减少百度统计的事件错误种类

Michael Wang 6 жил өмнө
parent
commit
471595c44f
1 өөрчлөгдсөн 58 нэмэгдсэн , 37 устгасан
  1. 58 37
      src/utils/monitors.js

+ 58 - 37
src/utils/monitors.js

@@ -1,7 +1,16 @@
 import Vue from "vue";
 import Vue from "vue";
 
 
 Vue.config.errorHandler = error => {
 Vue.config.errorHandler = error => {
-  window._hmt.push(["_trackEvent", "Vue组件错误", error.stack]);
+  // Vue.prototype.$httpNoAuth.post(
+  //   "/api/ecs_core/log/studentClient/" + "debug/007001",
+  //   error.stack.replace(/\n/g, '||||'),
+  //   {
+  //     headers: {
+  //       "Content-Type": "text/plain"
+  //     }
+  //   }
+  // );
+  window._hmt.push(["_trackEvent", "Vue组件错误"]);
   throw error;
   throw error;
 };
 };
 
 
@@ -18,47 +27,59 @@ Vue.config.errorHandler = error => {
 // };
 // };
 
 
 window.addEventListener("error", function(event) {
 window.addEventListener("error", function(event) {
-  window._hmt.push([
-    "_trackEvent",
-    "全局JS错误",
-    event.message,
-    `source: ${event.filename}\nlineno: ${event.lineno}\ncolno: ${
-      event.colno
-    }\nerror: ${event.error.stack}`
-  ]);
+  // Vue.prototype.$httpNoAuth.post(
+  //   "/api/ecs_core/log/studentClient/" + "debug/007002",
+  //  `message: ${event.message}\nsource: ${event.filename}\nlineno: ${event.lineno}\ncolno: ${
+  //   event.colno
+  // }\nerror: ${event.error.stack}`.replace(/\n/g, '||||'),
+  //   {
+  //     headers: {
+  //       "Content-Type": "text/plain"
+  //     }
+  //   }
+  // );
+  window._hmt.push(["_trackEvent", "全局JS错误", event.message]);
 });
 });
 
 
 window.addEventListener("unhandledrejection", function(event) {
 window.addEventListener("unhandledrejection", function(event) {
-  let detail = "";
-  if (event.reason.config) {
-    detail += "url:" + event.reason.config.url + "\n";
-    detail += "data: " + event.reason.config.data + "\n";
-    if (event.reason.request && event.reason.request.response) {
-      detail += "response: " + event.reason.request.response + "\n";
-    }
-  }
-  window._hmt.push([
-    "_trackEvent",
-    "全局Promise未处理错误",
-    event.reason,
-    detail
-  ]);
+  // let detail = "";
+  // if (event.reason.config) {
+  //   detail += "url:" + event.reason.config.url + "\n";
+  //   detail += "data: " + event.reason.config.data + "\n";
+  //   if (event.reason.request && event.reason.request.response) {
+  //     detail += "response: " + event.reason.request.response + "\n";
+  //   }
+  // }
+  // Vue.prototype.$httpNoAuth.post(
+  //   "/api/ecs_core/log/studentClient/" + "debug/007003",
+  //  `reason: ${event.reason}\ndetail: ${detail}`.replace(/\n/g, '||||'),
+  //   {
+  //     headers: {
+  //       "Content-Type": "text/plain"
+  //     }
+  //   }
+  // );
+  window._hmt.push(["_trackEvent", "全局Promise未处理错误", event.reason]);
 });
 });
 
 
 window.addEventListener("rejectionhandled", function(event) {
 window.addEventListener("rejectionhandled", function(event) {
   console.log("rejectionhandled"); // 似乎并不触发
   console.log("rejectionhandled"); // 似乎并不触发
-  let detail = "";
-  if (event.reason.config) {
-    detail += "url:" + event.reason.config.url + "\n";
-    detail += "data: " + event.reason.config.data + "\n";
-    if (event.reason.request && event.reason.request.response) {
-      detail += "response: " + event.reason.request.response + "\n";
-    }
-  }
-  window._hmt.push([
-    "_trackEvent",
-    "全局Promise已处理错误",
-    event.reason,
-    detail
-  ]);
+  // let detail = "";
+  // if (event.reason.config) {
+  //   detail += "url:" + event.reason.config.url + "\n";
+  //   detail += "data: " + event.reason.config.data + "\n";
+  //   if (event.reason.request && event.reason.request.response) {
+  //     detail += "response: " + event.reason.request.response + "\n";
+  //   }
+  // }
+  // Vue.prototype.$httpNoAuth.post(
+  //   "/api/ecs_core/log/studentClient/" + "debug/007004",
+  //  `reason: ${event.reason}\ndetail: ${detail}`.replace(/\n/g, '||||'),
+  //   {
+  //     headers: {
+  //       "Content-Type": "text/plain"
+  //     }
+  //   }
+  // );
+  window._hmt.push(["_trackEvent", "全局Promise已处理错误", event.reason]);
 });
 });