From 92e3cecb92ee9f7763ac27b74d5a3a7c31b65762 Mon Sep 17 00:00:00 2001 From: "DESKTOP-31IBRMI\\Administrator" <1509326266@qq.com> Date: Thu, 12 Sep 2024 15:30:21 +0800 Subject: [PATCH] feat(projects): @sa/axios: add response to flatRequest when success --- packages/axios/src/index.ts | 4 ++-- packages/axios/src/type.ts | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/packages/axios/src/index.ts b/packages/axios/src/index.ts index 0415bc3..c29d9d2 100644 --- a/packages/axios/src/index.ts +++ b/packages/axios/src/index.ts @@ -162,12 +162,12 @@ export function createFlatRequest, error: null }; } catch (error) { - return { data: null, error }; + return { data: null, error, response: (error as AxiosError).response }; } } as FlatRequestInstance; diff --git a/packages/axios/src/type.ts b/packages/axios/src/type.ts index 0ecbacb..644847f 100644 --- a/packages/axios/src/type.ts +++ b/packages/axios/src/type.ts @@ -69,7 +69,19 @@ export type CustomAxiosRequestConfig = Omit { + /** + * cancel the request by request id + * + * if the request provide abort controller sign from config, it will not collect in the abort controller map + * + * @param requestId + */ cancelRequest: (requestId: string) => void; + /** + * cancel all request + * + * if the request provide abort controller sign from config, it will not collect in the abort controller map + */ cancelAllRequest: () => void; /** you can set custom state in the request instance */ state: T; @@ -80,18 +92,20 @@ export interface RequestInstance> extends RequestIns (config: CustomAxiosRequestConfig): Promise>; } -export type FlatResponseSuccessData = { +export type FlatResponseSuccessData = { data: T; error: null; + response: AxiosResponse; }; export type FlatResponseFailData = { data: null; error: AxiosError; + response: AxiosResponse; }; export type FlatResponseData = - | FlatResponseSuccessData + | FlatResponseSuccessData | FlatResponseFailData; export interface FlatRequestInstance, ResponseData = any> extends RequestInstanceCommon {