Skip to content

Commit

Permalink
fix: statusCode 파싱 로직 제거 (#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
bbearcookie authored Nov 15, 2023
1 parent 1db5520 commit dc3cfc6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/core/api/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ export const formDataInstance: CustomAxiosInstance = axios.create({
});

const onSucessResponse = (res: AxiosResponse) => {
const { data, status } = res;
const { data } = res;

return { ...data, statusCode: status };
return data;
};

const onErrorResponse = (error: any) => Promise.reject(error);
Expand Down
29 changes: 12 additions & 17 deletions src/core/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,61 +20,56 @@ declare module '@tanstack/react-query' {
}
}

// statusCode를 포함한 응답 타입
export type ResponseWithStatusCode<T = any> = T & { statusCode: number };

// AxiosInstance 인터페이스의 내용을 그대로 확장하여 응답에 ResponseWithStatusCode를 적용한 인터페이스
// AxiosInstance 인터페이스의 내용을 그대로 확장하고 응답에서 data 만 파싱한 인터페이스
export interface CustomAxiosInstance extends AxiosInstance {
interceptors: {
request: AxiosInterceptorManager<InternalAxiosRequestConfig>;
response: AxiosInterceptorManager<AxiosResponse<any>>;
};
getUri(config?: AxiosRequestConfig): string;
request<T = any, R = ResponseWithStatusCode<T>, D = any>(
config: AxiosRequestConfig<D>
): Promise<R>;
get<T = any, R = ResponseWithStatusCode<T>, D = any>(
request<T = any, R = T, D = any>(config: AxiosRequestConfig<D>): Promise<R>;
get<T = any, R = T, D = any>(
url: string,
config?: AxiosRequestConfig<D>
): Promise<R>;
delete<T = any, R = ResponseWithStatusCode<T>, D = any>(
delete<T = any, R = T, D = any>(
url: string,
config?: AxiosRequestConfig<D>
): Promise<R>;
head<T = any, R = ResponseWithStatusCode<T>, D = any>(
head<T = any, R = T, D = any>(
url: string,
config?: AxiosRequestConfig<D>
): Promise<R>;
options<T = any, R = ResponseWithStatusCode<T>, D = any>(
options<T = any, R = T, D = any>(
url: string,
config?: AxiosRequestConfig<D>
): Promise<R>;
post<T = any, R = ResponseWithStatusCode<T>, D = any>(
post<T = any, R = T, D = any>(
url: string,
data?: D,
config?: AxiosRequestConfig<D>
): Promise<R>;
put<T = any, R = ResponseWithStatusCode<T>, D = any>(
put<T = any, R = T, D = any>(
url: string,
data?: D,
config?: AxiosRequestConfig<D>
): Promise<R>;
patch<T = any, R = ResponseWithStatusCode<T>, D = any>(
patch<T = any, R = T, D = any>(
url: string,
data?: D,
config?: AxiosRequestConfig<D>
): Promise<R>;
postForm<T = any, R = ResponseWithStatusCode<T>, D = any>(
postForm<T = any, R = T, D = any>(
url: string,
data?: D,
config?: AxiosRequestConfig<D>
): Promise<R>;
putForm<T = any, R = ResponseWithStatusCode<T>, D = any>(
putForm<T = any, R = T, D = any>(
url: string,
data?: D,
config?: AxiosRequestConfig<D>
): Promise<R>;
patchForm<T = any, R = ResponseWithStatusCode<T>, D = any>(
patchForm<T = any, R = T, D = any>(
url: string,
data?: D,
config?: AxiosRequestConfig<D>
Expand Down

0 comments on commit dc3cfc6

Please sign in to comment.