|
@@ -0,0 +1,64 @@
|
|
|
+import Vue from "vue";
|
|
|
+
|
|
|
+Vue.config.errorHandler = error => {
|
|
|
+ window._hmt.push(["_trackEvent", "Vue组件错误", error.stack]);
|
|
|
+ throw error;
|
|
|
+};
|
|
|
+
|
|
|
+// window.onerror = function(message, source, lineno, colno, error) {
|
|
|
+// console.log(message);
|
|
|
+// window._hmt.push([
|
|
|
+// "_trackEvent",
|
|
|
+// "全局JS错误",
|
|
|
+// message,
|
|
|
+// `source: ${source}\nlineno: ${lineno}\ncolno: ${colno}\nerror: ${
|
|
|
+// error.stack
|
|
|
+// }`
|
|
|
+// ]);
|
|
|
+// };
|
|
|
+
|
|
|
+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}`
|
|
|
+ ]);
|
|
|
+});
|
|
|
+
|
|
|
+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
|
|
|
+ ]);
|
|
|
+});
|
|
|
+
|
|
|
+window.addEventListener("rejectionhandled", function(event) {
|
|
|
+ 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
|
|
|
+ ]);
|
|
|
+});
|