Преглед изворни кода

fix: 响应拦截器兜底msg,对格式进行判断

fix: 11
lanjianrong пре 3 година
родитељ
комит
ed9756fe7d
2 измењених фајлова са 10 додато и 10 уклоњено
  1. 1 1
      config/routes.ts
  2. 9 9
      src/app.tsx

+ 1 - 1
config/routes.ts

@@ -9,7 +9,7 @@
           {
             name: 'login',
             path: '/user/login',
-            component: './user/Login'
+            component: './User/Login'
           }
         ]
       }

+ 9 - 9
src/app.tsx

@@ -1,11 +1,12 @@
 import type { Settings as LayoutSettings } from '@ant-design/pro-layout'
 import { notification } from 'antd'
 import type { RequestConfig, RunTimeLayoutConfig } from '@umijs/max'
-import { getIntl, getLocale, history } from '@umijs/max'
+import { history } from '@umijs/max'
 import RightContent from '@/components/RightContent'
 import { currentUser as queryCurrentUser } from './services/user/api'
 import consts from './utils/consts'
 import defaultSettings from '../config/defaultSettings'
+import { isNullOrUnDef, isObject } from './utils/is'
 const loginPath = '/user/login'
 
 /**
@@ -109,14 +110,13 @@ export const request: RequestConfig = {
   },
   responseInterceptors: [
     async response => {
-      const { data, code: errorCode, msg: errorMessage } = response.data
-      if (!errorCode || errorCode !== consts.RET_CODE.SUCCESS) {
-        if (errorCode !== consts.RET_CODE.SUCCESS) {
-          const error: any = new Error(errorMessage)
-          error.name = 'BizError'
-          error.info = { errorCode, errorMessage, data }
-          throw error
-        }
+      const { data, code: errorCode, msg } = response.data
+      if (isNullOrUnDef(errorCode) || errorCode !== consts.RET_CODE.SUCCESS) {
+        const errorMessage = isObject(msg) ? JSON.stringify(msg) : msg
+        const error: any = new Error(errorMessage)
+        error.name = 'BizError'
+        error.info = { errorCode, errorMessage, data }
+        throw error
       }
       return Promise.resolve(response)
     }