浏览代码

优化请求

ZaiZai 2 年之前
父节点
当前提交
4e9d97b9b6
共有 2 个文件被更改,包括 7 次插入4 次删除
  1. 6 2
      src/api/request/httpApi.js
  2. 1 2
      src/api/request/index.js

+ 6 - 2
src/api/request/httpApi.js

@@ -48,6 +48,10 @@ const getResData = async (response, error = false) => {
 
 //获取msg消息内容
 const getMsgVal = (response) => {
-    const {msg, error_description} = getObjValue(response.data)
-    return msg || error_description || '未知错误';
+    const {code, msg, error_description} = getObjValue(response.data)
+    if (code === 404) {
+        return '服务器异常,请联系管理员!';
+    } else {
+        return msg || error_description || '未知错误';
+    }
 }

+ 1 - 2
src/api/request/index.js

@@ -44,10 +44,9 @@ axios.interceptors.response.use(res => {
     res.config.metadata.endTime = new Date()
     //获取状态码
     const status = res.data?.code || res.status;
-    const message = res.data?.msg || res.data['error_description'] || '未知错误';
     //如果是401则跳转到登录页面
     if (status === 401) {
-        window.$message?.error(message || '身份失效!');
+        window.$message?.error('身份失效,请重新登录!');
         router.push({path: '/login'})
     }
     // 如果请求为非200, 自行catch逻辑处理