ソースを参照

网络请求错误日志

Michael Wang 5 年 前
コミット
fb4440fa4f
1 ファイル変更3 行追加43 行削除
  1. 3 43
      src/utils/axios.js

+ 3 - 43
src/utils/axios.js

@@ -4,6 +4,7 @@ import { loadProgressBar } from "./axiosProgress";
 import cachingGet from "./axiosCache";
 import cachingGet from "./axiosCache";
 import { Message, Modal } from "iview";
 import { Message, Modal } from "iview";
 import router from "../router";
 import router from "../router";
+import { createLog } from "@/utils/logger";
 //axios配置 start
 //axios配置 start
 
 
 const qmInstance = axios.create({});
 const qmInstance = axios.create({});
@@ -48,6 +49,7 @@ qmInstance.interceptors.request.use(
       duration: 15,
       duration: 15,
       closable: true,
       closable: true,
     });
     });
+    createLog({ action: "axios request", error: JSON.stringify(error) });
     return Promise.resolve(error);
     return Promise.resolve(error);
   }
   }
 );
 );
@@ -58,6 +60,7 @@ qmInstance.interceptors.response.use(
     return response;
     return response;
   },
   },
   error => {
   error => {
+    createLog({ action: "axios response", error: JSON.stringify(error) });
     if (!error.response) {
     if (!error.response) {
       // "Network Error" 网络不通,直接返回
       // "Network Error" 网络不通,直接返回
       // "timeout of 30000ms exceeded" 连接超时,可能是客户端原因,也可能是服务器原因
       // "timeout of 30000ms exceeded" 连接超时,可能是客户端原因,也可能是服务器原因
@@ -223,49 +226,6 @@ qmInstance.get = cachingGet(qmInstance.get, [
 ]);
 ]);
 loadProgressBar(qmInstance);
 loadProgressBar(qmInstance);
 
 
-// const upyunInstance = axios.create({});
-// FIXME: axios bug. wait 0.19 release. https://github.com/axios/axios/issues/385
-// upyunInstance.defaults.headers.common = {};
-// // upyunInstance.defaults.headers.common["Authorization"] = UPYUN_HEADER_AUTH;
-
-// let __upyunAuth = null;
-// let __upyunBucketUrl = null;
-// upyunInstance.interceptors.request.use(
-//   config => {
-//     if (__upyunAuth) {
-//       config.baseURL = __upyunBucketUrl;
-//       config.headers.common["Authorization"] = __upyunAuth;
-//       return config;
-//     } else {
-//       return qmInstance
-//         .get("/api/ecs_oe_student_face/upyun")
-//         .then(res => {
-//           __upyunBucketUrl = res.data.bucketUrl;
-//           config.baseURL = __upyunBucketUrl;
-//           const authorization =
-//             "Basic " +
-//             btoa(atob(res.data.upyunOperator) + ":" + atob(res.data.upyunCred));
-//           __upyunAuth = authorization;
-//           config.headers.common["Authorization"] = __upyunAuth;
-//           return config;
-//         })
-//         .catch(err => {
-//           console.log(err);
-//         });
-//     }
-//   },
-//   error => {
-//     Message.error({
-//       content: error,
-//       duration: 10,
-//       closable: true
-//     });
-//     return Promise.resolve(error);
-//   }
-// );
-
-// loadProgressBar(upyunInstance);
-
 Vue.prototype.$http = qmInstance;
 Vue.prototype.$http = qmInstance;
 // Vue.prototype.$upyunhttp = upyunInstance;
 // Vue.prototype.$upyunhttp = upyunInstance;
 export default {
 export default {