From 6f72e6c285fdc4bd51a9e489bbcbff4cfbe2273b Mon Sep 17 00:00:00 2001 From: loicduong Date: Sat, 7 Sep 2024 15:51:43 +0700 Subject: [PATCH] feat(core): add response to flatRequest when success in @sa/axios --- packages/axios/src/index.ts | 4 ++-- packages/axios/src/type.ts | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/axios/src/index.ts b/packages/axios/src/index.ts index c9359c0..7cd9f02 100644 --- a/packages/axios/src/index.ts +++ b/packages/axios/src/index.ts @@ -162,13 +162,13 @@ 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 ed8e046..0256969 100644 --- a/packages/axios/src/type.ts +++ b/packages/axios/src/type.ts @@ -92,18 +92,19 @@ export interface RequestInstance> extends RequestIns (config: CustomAxiosRequestConfig): Promise> } -export interface FlatResponseSuccessData { +export type FlatResponseSuccessData = { data: T error: null + response: AxiosResponse } - export interface FlatResponseFailData { data: null error: AxiosError + response: AxiosResponse } export type FlatResponseData = - | FlatResponseSuccessData + | FlatResponseSuccessData | FlatResponseFailData export interface FlatRequestInstance, ResponseData = any> extends RequestInstanceCommon {