From c0e40fa01eef776cca97f7550684a1bc5e6d12ac Mon Sep 17 00:00:00 2001 From: Tianyuan Zhang Date: Thu, 7 Jul 2022 15:39:48 +0800 Subject: [PATCH] refactor: update class AxiosTransform (#2041) rename transformRequestHook to transformResponseHook --- src/utils/http/axios/Axios.ts | 6 +++--- src/utils/http/axios/axiosTransform.ts | 4 ++-- src/utils/http/axios/index.ts | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/utils/http/axios/Axios.ts b/src/utils/http/axios/Axios.ts index 60ff4bd2..f683a887 100644 --- a/src/utils/http/axios/Axios.ts +++ b/src/utils/http/axios/Axios.ts @@ -199,7 +199,7 @@ export class VAxios { const opt: RequestOptions = Object.assign({}, requestOptions, options); - const { beforeRequestHook, requestCatchHook, transformRequestHook } = transform || {}; + const { beforeRequestHook, requestCatchHook, transformResponseHook } = transform || {}; if (beforeRequestHook && isFunction(beforeRequestHook)) { conf = beforeRequestHook(conf, opt); } @@ -211,9 +211,9 @@ export class VAxios { this.axiosInstance .request>(conf) .then((res: AxiosResponse) => { - if (transformRequestHook && isFunction(transformRequestHook)) { + if (transformResponseHook && isFunction(transformResponseHook)) { try { - const ret = transformRequestHook(res, opt); + const ret = transformResponseHook(res, opt); resolve(ret); } catch (err) { reject(err || new Error('request error!')); diff --git a/src/utils/http/axios/axiosTransform.ts b/src/utils/http/axios/axiosTransform.ts index beeac6cb..f65def92 100644 --- a/src/utils/http/axios/axiosTransform.ts +++ b/src/utils/http/axios/axiosTransform.ts @@ -18,9 +18,9 @@ export abstract class AxiosTransform { beforeRequestHook?: (config: AxiosRequestConfig, options: RequestOptions) => AxiosRequestConfig; /** - * @description: Request successfully processed + * @description: 处理响应数据 */ - transformRequestHook?: (res: AxiosResponse, options: RequestOptions) => any; + transformResponseHook?: (res: AxiosResponse, options: RequestOptions) => any; /** * @description: 请求失败处理 diff --git a/src/utils/http/axios/index.ts b/src/utils/http/axios/index.ts index 5be1a904..5253a3ce 100644 --- a/src/utils/http/axios/index.ts +++ b/src/utils/http/axios/index.ts @@ -28,9 +28,9 @@ const { createMessage, createErrorModal } = useMessage(); */ const transform: AxiosTransform = { /** - * @description: 处理请求数据。如果数据不是预期格式,可直接抛出错误 + * @description: 处理响应数据。如果数据不是预期格式,可直接抛出错误 */ - transformRequestHook: (res: AxiosResponse, options: RequestOptions) => { + transformResponseHook: (res: AxiosResponse, options: RequestOptions) => { const { t } = useI18n(); const { isTransformResponse, isReturnNativeResponse } = options; // 是否返回原生响应头 比如:需要获取响应头时使用该属性