Explorar o código

JSON.parse可能出错

Michael Wang %!s(int64=5) %!d(string=hai) anos
pai
achega
bc3b4dcc49
Modificáronse 1 ficheiros con 7 adicións e 1 borrados
  1. 7 1
      src/features/OnlineExam/Examing/ws.js

+ 7 - 1
src/features/OnlineExam/Examing/ws.js

@@ -131,7 +131,13 @@ export function getQRCode(order, transferFileType, testEnv) {
 
 function processWSMessage(event) {
   // console.log("get ws msg: ", event);
-  const res = JSON.parse(event.data);
+  let res;
+  try {
+    res = JSON.parse(event.data);
+  } catch (error) {
+    window._hmt.push(["_trackEvent", "websocket", "JSON.parse出错" + error]);
+    return;
+  }
   if (res.eventType !== "HEARTBEAT" && !res.isSuccess) {
     Message.error({
       content: res.errorMessage,