Ver Fonte

重试待考列表和断点续考接口

Michael Wang há 5 anos atrás
pai
commit
f6acd5a4db
3 ficheiros alterados com 40 adições e 6 exclusões
  1. 28 4
      src/features/OnlineExam/OnlineExamHome.vue
  2. 5 2
      src/mixins/mixins.js
  3. 7 0
      src/utils/axios.js

+ 28 - 4
src/features/OnlineExam/OnlineExamHome.vue

@@ -99,11 +99,35 @@ export default {
   },
   async mounted() {
     window._hmt.push(["_trackEvent", "在线考试列表页面", "进入页面"]);
-    const res = await this.$http.get(
-      "/api/ecs_oe_student/examControl/queryExamList"
-    );
 
-    this.courses = res.data;
+    let examListRes;
+    for (let i = 0; i < 4; i++) {
+      examListRes = await this.$http.get(
+        "/api/ecs_oe_student/examControl/queryExamList"
+      );
+      if (examListRes.status === 503) {
+        await new Promise(resolve => setTimeout(() => resolve(), 2000));
+        continue;
+      } else if (examListRes.status === 200) {
+        break;
+      }
+    }
+
+    if (examListRes.status !== 200) {
+      window._hmt.push([
+        "_trackEvent",
+        "待考列表获取失败",
+        "调用待考列表获取接口超过失败次数",
+      ]);
+      this.$Message.error({
+        content: "服务器繁忙(503)!请稍后重试。",
+        duration: 15,
+        closable: true,
+      });
+      return;
+    } else {
+      this.courses = examListRes.data;
+    }
 
     try {
       const noticeRes = (await this.$http.get(

+ 5 - 2
src/mixins/mixins.js

@@ -41,14 +41,17 @@ Vue.mixin({
           examingRes = await this.$http.get(
             "/api/ecs_oe_student/examControl/checkExamInProgress"
           );
-          if (examingRes.data.code === "S-101000") {
+          if (
+            examingRes.status === 503 ||
+            examingRes.data.code === "S-101000"
+          ) {
             await new Promise(resolve => setTimeout(() => resolve(), 2000));
             continue;
           } else if (examingRes.data.code === "000000") {
             break;
           }
         }
-        if (examingRes.data.code !== "000000") {
+        if (examingRes.status !== 200 || examingRes.data.code !== "000000") {
           window._hmt.push([
             "_trackEvent",
             "断点续考处理异常",

+ 7 - 0
src/utils/axios.js

@@ -126,6 +126,13 @@ qmInstance.interceptors.response.use(
       });
       return;
     } else if (status == 503) {
+      const deal503Apis = [
+        "/api/ecs_oe_student/examControl/checkExamInProgress",
+        "/api/ecs_oe_student/examControl/queryExamList",
+      ];
+      if (deal503Apis.includes(error.config.url)) {
+        return Promise.resolve({ status: 503 });
+      }
       window._hmt.push([
         "_trackEvent",
         location.pathname,