Browse Source

feat(request): 调整请求成功判断逻辑以支持登录接口

zhangtao 1 week ago
parent
commit
7aea246a6b
3 changed files with 5 additions and 3 deletions
  1. 2 2
      .env.test
  2. 1 1
      packages/axios/src/constant.ts
  3. 2 0
      src/service/request/index.ts

+ 2 - 2
.env.test

@@ -2,12 +2,12 @@
 # VITE_SERVICE_BASE_URL=http://74949mkfh190.vicp.fun
 # VITE_SERVICE_BASE_URL=http://192.168.1.253:8114 #付
 # VITE_SERVICE_BASE_URL=http://192.168.0.157:8114 #王
-VITE_SERVICE_BASE_URL=http://192.168.1.166:8114 #张
+# VITE_SERVICE_BASE_URL=http://192.168.1.166:8114 #张
 # VITE_SERVICE_BASE_URL=http://192.168.1.66:8114 #邓
 # VITE_SERVICE_BASE_URL=https://mock.apifox.cn/m1/3109515-0-default
 # VITE_SERVICE_BASE_URL=https://shop.platform.zswlgz.com #服务器
 # VITE_SERVICE_BASE_URL=/plt #测试打包服务器
-# VITE_SERVICE_BASE_URL=http://47.109.84.152:8114 #测试本地服务器
+VITE_SERVICE_BASE_URL=http://47.109.84.152:8114 #测试本地服务器
 
 
 # other backend service base url, test environment

+ 1 - 1
packages/axios/src/constant.ts

@@ -2,4 +2,4 @@
 export const REQUEST_ID_KEY = 'X-Request-Id';
 
 /** the backend error code key */
-export const BACKEND_ERROR_CODE = 'BACKEND_ERROR';
+export const BACKEND_ERROR_CODE = 'ERR_BAD_RESPONSE';

+ 2 - 0
src/service/request/index.ts

@@ -36,7 +36,9 @@ export const request = createFlatRequest(
       // when the backend response code is "0000"(default), it means the request is success
       // to change this logic by yourself, you can modify the `VITE_SERVICE_SUCCESS_CODE` in `.env` file
       // return String(response.data.code) === import.meta.env.VITE_SERVICE_SUCCESS_CODE;
+
       const isLogin = response.config?.url?.includes('platformLogin');
+
       const isSuccess =
         (isLogin ? String(response.status) : String(response.data.code)) === import.meta.env.VITE_SERVICE_SUCCESS_CODE;
       return isSuccess;