Просмотр исходного кода

JSON.stingify 避免触发循环引用的对象

Michael Wang 4 лет назад
Родитель
Сommit
53ef6d4671
1 измененных файлов с 10 добавлено и 0 удалено
  1. 10 0
      src/utils/monitors.js

+ 10 - 0
src/utils/monitors.js

@@ -43,6 +43,16 @@ window.addEventListener("error", function (event) {
 window.addEventListener("unhandledrejection", function (event) {
   // 此错误由上传阿里云日志触发,会被重复好几次
   // 改为fetch,阿里云日志的错误不应该触发到这里
+
+  // 这会触发Circular JSON error
+  if (event.reason.name === "NavigationDuplicated") {
+    createLog({
+      action: "unhandledrejection错误",
+      page: window.location.pathname,
+      reason: "NavigationDuplicated",
+    });
+    return;
+  }
   console.log(
     "unhandledrejection event",
     event,