瀏覽代碼

参数解析

CzRger 1 周之前
父節點
當前提交
9642b26c02
共有 1 個文件被更改,包括 9 次插入1 次删除
  1. 9 1
      src/api/interceptors.ts

+ 9 - 1
src/api/interceptors.ts

@@ -75,6 +75,14 @@ export class Interceptors {
     if (hasLogin) {
       console.error('错误接口:' + res.request.responseURL)
       const exportLog = () => {
+        let params = res.config.data
+        if (res.config.data instanceof FormData) {
+          const obj = {}
+          res.config.data.entries().forEach((v: any) => {
+            obj[v[0]] = v[1]
+          })
+          params = obj
+        }
         let str = ''
         const arr = [
           `错误日期:${YMDHms(res.headers.date)}`,
@@ -82,7 +90,7 @@ export class Interceptors {
           `接口地址:${res.request.responseURL}`,
           `接口状态:${res.status} ${res.statusText}`,
           `请求Token:${res.config.headers.Authorization}`,
-          `请求参数:${res.config.data || ''}`,
+          `请求参数:${(typeof params === 'string' ? params : JSON.stringify(params)) || ''}`,
           `返回结果:${res.request.response}`,
         ]
         arr.forEach((v) => {