Bladeren bron

fix:修改提示文件下载报错问题

lazy 6 dagen geleden
bovenliggende
commit
4a69b57a02
1 gewijzigde bestanden met toevoegingen van 21 en 8 verwijderingen
  1. 21 8
      src/utils/request.js

+ 21 - 8
src/utils/request.js

@@ -114,14 +114,27 @@ service.interceptors.response.use(
   },
   error => {
     loadingInstance && loadingInstance.close()
-    const { msg } = error.response.data
-    console.log('err' + error) // for debug
-    // '后端异常:' +
-    Message({
-      message: msg,
-      type: 'error',
-      duration: 5 * 1000
-    })
+    if (error.response.data instanceof ArrayBuffer) {
+      const textDecoder = new TextDecoder('utf-8')
+      const errorText = textDecoder.decode(error.response.data)
+
+      const errorJson = JSON.parse(errorText)
+
+      Message({
+        message: errorJson.msg || '文件下载失败',
+        type: 'error',
+        duration: 5 * 1000
+      })
+    } else {
+      const { msg } = error.response.data
+      console.log('err' + error) // for debug
+      // '后端异常:' +
+      Message({
+        message: msg,
+        type: 'error',
+        duration: 5 * 1000
+      })
+    }
     resetLogin(error.response)
     return Promise.reject(error)
   }