diff --git a/src/utils/fetcher/AuthInterceptor.ts b/src/utils/fetcher/AuthInterceptor.ts index bd4b0d4b..db0435c2 100644 --- a/src/utils/fetcher/AuthInterceptor.ts +++ b/src/utils/fetcher/AuthInterceptor.ts @@ -1,4 +1,4 @@ -import {AxiosResponse} from 'axios' +import {AxiosError, AxiosResponse} from 'axios' import {RESPONSE} from '$constants' import {Response} from '$types/response' import {AccessTokenError, CommonApiError, RedirectArror} from './ApiError' @@ -6,7 +6,7 @@ import {AccessTokenError, CommonApiError, RedirectArror} from './ApiError' /** * @todo 회원 인증 에러 추가 */ -export function AuthInterceptor(res: AxiosResponse>): T { +export function resolveInterceptor(res: AxiosResponse>): T { const code = res.data.code switch (code) { @@ -20,3 +20,23 @@ export function AuthInterceptor(res: AxiosResponse>): T { return res.data.result } } + +class ErrorTable { + statusCode?: number + cookie?: string + requestUrl?: string + constructor(statusCode?: number, cookie?: string, requestUrl?: string) { + this.statusCode = statusCode + this.cookie = cookie + this.requestUrl = requestUrl + } +} + +export function rejectInterceptor(error: AxiosError) { + const statusCode = error.response?.status + const {headers, url} = error.config + const errorTable = new ErrorTable(statusCode, headers?.Authorization, url) + + console.table(errorTable) + throw error +} diff --git a/src/utils/fetcher/withAxios.ts b/src/utils/fetcher/withAxios.ts index 7c07f926..9e8a40f3 100644 --- a/src/utils/fetcher/withAxios.ts +++ b/src/utils/fetcher/withAxios.ts @@ -5,7 +5,7 @@ import {isSSR} from '$utils/env' import {createMockAxiosInstance} from '$utils/__mocks__/fetcher/createMockAxiosInstance' import axios, {AxiosInstance} from 'axios' import {HOST_URL} from 'config' -import {AuthInterceptor} from './AuthInterceptor' +import {rejectInterceptor, resolveInterceptor} from './AuthInterceptor' export interface MockAxiosInstance { target: AxiosInstance @@ -62,7 +62,7 @@ export const createErrorResponse = (data: T): Response => ({ const createAxiosInstance = () => { const instance = axios.create() - instance.interceptors.response.use(AuthInterceptor) + instance.interceptors.response.use(resolveInterceptor, rejectInterceptor) return extendWithMock(instance) }