From 1056ec32283c082dc9be6f4439345ec367180db9 Mon Sep 17 00:00:00 2001 From: Chiman2937 Date: Sun, 14 Dec 2025 16:29:28 +0900 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20axios=20=EC=9D=B8=ED=84=B0=EC=85=89?= =?UTF-8?q?=ED=84=B0=20401=20redirect=20=EB=A1=9C=EC=A7=81=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/core/index.ts | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/api/core/index.ts b/src/api/core/index.ts index 51c9e952..1d1fcbfc 100644 --- a/src/api/core/index.ts +++ b/src/api/core/index.ts @@ -1,5 +1,3 @@ -import { notFound, redirect } from 'next/navigation'; - import axios from 'axios'; import { CommonErrorResponse, CommonSuccessResponse } from '@/types/service/common'; @@ -37,16 +35,6 @@ baseAPI.interceptors.response.use( return response; }, async (error) => { - const status = error.response?.status; - if (status) { - if (status === 401) { - redirect('/signin?error=unauthorized'); - } - if (status === 404) { - notFound(); - } - } - const errorResponse: CommonErrorResponse = error.response?.data || { type: 'about:blank', title: 'Network Error', @@ -56,6 +44,23 @@ baseAPI.interceptors.response.use( errorCode: 'NETWORK_ERROR', }; + const { status } = errorResponse; + const isServer = typeof window === 'undefined'; + + if (status === 401) { + if (isServer) { + const { redirect } = await import('next/navigation'); + redirect('/login'); + } else { + const currentPath = window.location.pathname + window.location.search; + window.location.href = `/login?error=unauthorized&path=${encodeURIComponent(currentPath)}`; + } + } + if (status === 404) { + const { notFound } = await import('next/navigation'); + notFound(); + } + throw errorResponse; }, ); From 217fb9d0de2147529d694186ea175f98b96f5cfc Mon Sep 17 00:00:00 2001 From: Chiman2937 Date: Sun, 14 Dec 2025 16:46:40 +0900 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20notFound()=EA=B0=80=20=EC=84=9C?= =?UTF-8?q?=EB=B2=84=EC=97=90=EC=84=9C=EB=A7=8C=20=EC=8B=A4=ED=96=89?= =?UTF-8?q?=EB=90=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95,=20status=20fa?= =?UTF-8?q?llback=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/core/index.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/api/core/index.ts b/src/api/core/index.ts index 1d1fcbfc..1b3310f2 100644 --- a/src/api/core/index.ts +++ b/src/api/core/index.ts @@ -44,7 +44,7 @@ baseAPI.interceptors.response.use( errorCode: 'NETWORK_ERROR', }; - const { status } = errorResponse; + const status = error.response?.status ?? errorResponse.status; const isServer = typeof window === 'undefined'; if (status === 401) { @@ -52,13 +52,18 @@ baseAPI.interceptors.response.use( const { redirect } = await import('next/navigation'); redirect('/login'); } else { + if (window.location.pathname === '/login') { + throw errorResponse; + } const currentPath = window.location.pathname + window.location.search; window.location.href = `/login?error=unauthorized&path=${encodeURIComponent(currentPath)}`; } } if (status === 404) { - const { notFound } = await import('next/navigation'); - notFound(); + if (isServer) { + const { notFound } = await import('next/navigation'); + notFound(); + } } throw errorResponse;