Selaa lähdekoodia

日志中,不应该包括token

Michael Wang 5 vuotta sitten
vanhempi
commit
c4f5123ad1

+ 27 - 8
src/components/FaceRecognition/FaceRecognition.vue

@@ -196,7 +196,9 @@ export default {
                 detail: error,
                 errorName: error.name,
                 errorMessage: error.message,
-                errorStringify: JSON.stringify(error),
+                errorStringify: JSON.stringify(error, (key, value) =>
+                  key === "token" ? "" : value
+                ),
               });
               this.$Message.error({
                 content: "摄像头没有正常启用: " + error,
@@ -271,7 +273,12 @@ export default {
           }
 
           const errorMsgLog =
-            errMsg + (typeof errMsg === "object" ? JSON.stringify(errMsg) : "");
+            errMsg +
+            (typeof errMsg === "object"
+              ? JSON.stringify(errMsg, (key, value) =>
+                  key === "token" ? "" : value
+                )
+              : "");
           this.logger({
             action: "摄像头打开失败",
             detail: "无法启用摄像头",
@@ -352,7 +359,9 @@ export default {
         console.log("定时抓拍流程失败", error);
         this.logger({
           action: "定时抓拍流程失败",
-          detail: JSON.stringify(error),
+          detail: JSON.stringify(error, (key, value) =>
+            key === "token" ? "" : value
+          ),
         });
         window._hmt.push([
           "_trackEvent",
@@ -557,13 +566,17 @@ export default {
           this.logger({
             page: "摄像头框",
             detail: "抓拍照片保存失败",
-            error: JSON.stringify(error),
+            error: JSON.stringify(error, (key, value) =>
+              key === "token" ? "" : value
+            ),
           });
           window._hmt.push([
             "_trackEvent",
             "摄像头框",
             "抓拍照片保存失败",
-            JSON.stringify(error),
+            JSON.stringify(error, (key, value) =>
+              key === "token" ? "" : value
+            ),
           ]);
           throw error;
         }
@@ -578,7 +591,9 @@ export default {
         this.logger({
           page: "摄像头框",
           detail: "保存抓拍照片到服务器失败!",
-          error: JSON.stringify(e),
+          error: JSON.stringify(e, (key, value) =>
+            key === "token" ? "" : value
+          ),
         });
         window._hmt.push([
           "_trackEvent",
@@ -659,7 +674,9 @@ export default {
                     this.logger({
                       page: "摄像头框",
                       type: "虚拟摄像头-读取摄像头列表失败",
-                      error: JSON.stringify(error),
+                      error: JSON.stringify(error, (key, value) =>
+                        key === "token" ? "" : value
+                      ),
                     });
                     window._hmt.push([
                       "_trackEvent",
@@ -706,7 +723,9 @@ export default {
           this.logger({
             page: "摄像头框",
             action: "设置获取抓拍结果失败!",
-            error: JSON.stringify(error),
+            error: JSON.stringify(error, (key, value) =>
+              key === "token" ? "" : value
+            ),
           });
           this.$Message.error({
             content: "设置获取抓拍结果失败!",

+ 9 - 2
src/features/OnlineExam/Examing/ExamingHome.vue

@@ -749,7 +749,9 @@ export default {
           console.log(error);
           this.logger({
             action: "提交答案失败",
-            detail: JSON.stringify(error),
+            detail: JSON.stringify(error, (key, value) =>
+              key === "token" ? "" : value
+            ),
           });
           this.$Message.error({
             content: "提交答案失败",
@@ -900,7 +902,12 @@ export default {
           closable: true,
         });
         console.log(e);
-        this.logger({ action: "交卷失败", detail: JSON.stringify(e) });
+        this.logger({
+          action: "交卷失败",
+          detail: JSON.stringify(e, (key, value) =>
+            key === "token" ? "" : value
+          ),
+        });
       }
       this.submitLock = false;
       this.$Spin.hide();

+ 3 - 1
src/features/OnlineExam/Examing/RemainTime.vue

@@ -116,7 +116,9 @@ export default {
             action: "发出心跳",
             error: "心跳失败",
             detail: `考试剩余时间:${this.remainTime / 1000}`,
-            extraDetail: JSON.stringify(error),
+            extraDetail: JSON.stringify(error, (key, value) =>
+              key === "token" ? "" : value
+            ),
           });
         }
         this.heartbeatErrorNum++;

+ 12 - 2
src/utils/axios.js

@@ -49,7 +49,12 @@ qmInstance.interceptors.request.use(
       duration: 15,
       closable: true,
     });
-    createLog({ action: "axios request", error: JSON.stringify(error) });
+    createLog({
+      action: "axios request",
+      error: JSON.stringify(error, (key, value) =>
+        key === "token" ? "" : value
+      ),
+    });
     return Promise.resolve(error);
   }
 );
@@ -60,7 +65,12 @@ qmInstance.interceptors.response.use(
     return response;
   },
   error => {
-    createLog({ action: "axios response", error: JSON.stringify(error) });
+    createLog({
+      action: "axios response",
+      error: JSON.stringify(error, (key, value) =>
+        key === "token" ? "" : value
+      ),
+    });
     if (!error.response) {
       // "Network Error" 网络不通,直接返回
       // "timeout of 30000ms exceeded" 连接超时,可能是客户端原因,也可能是服务器原因