Skip to content

Commit aace819

Browse files
committed
feat(packages): @sa/axios: add response to flatRequest when success
1 parent 60366c2 commit aace819

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

packages/axios/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,12 @@ export function createFlatRequest<ResponseData = any, State = Record<string, unk
162162
if (responseType === 'json') {
163163
const data = opts.transformBackendResponse(response);
164164

165-
return { data, error: null };
165+
return { data, error: null, response };
166166
}
167167

168168
return { data: response.data as MappedType<R, T>, error: null };
169169
} catch (error) {
170-
return { data: null, error };
170+
return { data: null, error, response: (error as AxiosError<ResponseData>).response };
171171
}
172172
} as FlatRequestInstance<State, ResponseData>;
173173

packages/axios/src/type.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,18 +92,20 @@ export interface RequestInstance<S = Record<string, unknown>> extends RequestIns
9292
<T = any, R extends ResponseType = 'json'>(config: CustomAxiosRequestConfig<R>): Promise<MappedType<R, T>>;
9393
}
9494

95-
export type FlatResponseSuccessData<T = any> = {
95+
export type FlatResponseSuccessData<T = any, ResponseData = any> = {
9696
data: T;
9797
error: null;
98+
response: AxiosResponse<ResponseData>;
9899
};
99100

100101
export type FlatResponseFailData<ResponseData = any> = {
101102
data: null;
102103
error: AxiosError<ResponseData>;
104+
response: AxiosResponse<ResponseData>;
103105
};
104106

105107
export type FlatResponseData<T = any, ResponseData = any> =
106-
| FlatResponseSuccessData<T>
108+
| FlatResponseSuccessData<T, ResponseData>
107109
| FlatResponseFailData<ResponseData>;
108110

109111
export interface FlatRequestInstance<S = Record<string, unknown>, ResponseData = any> extends RequestInstanceCommon<S> {

0 commit comments

Comments
 (0)