diff --git a/src/apis/instance.js b/src/apis/instance.js index 9fffb83..4159001 100644 --- a/src/apis/instance.js +++ b/src/apis/instance.js @@ -1,21 +1,21 @@ import axios from "axios"; -import Cookies from 'js-cookie'; -const accessToken = Cookies.get('access_token'); +import Cookies from "js-cookie"; +const accessToken = Cookies.get("access_token"); export const instance = axios.create({ baseURL: import.meta.env.VITE_BASE_URL, withCredentials: true, headers: { - Authorization: `Bearer ${Cookies.get('access_token')}`, + Authorization: `Bearer ${Cookies.get("access_token")}`, }, timeout: 10000, // 10초 타임아웃 설정 }); instance.interceptors.request.use( (config) => { - const accessToken = Cookies.get('access_token'); // 요청을 보낼 때마다 쿠키에서 액세스 토큰을 가져옵니다. + const accessToken = Cookies.get("access_token"); // 요청을 보낼 때마다 쿠키에서 액세스 토큰을 가져옵니다. if (accessToken) { - config.headers['Authorization'] = `Bearer ${accessToken}`; // 액세스 토큰이 있으면 헤더에 추가합니다. + config.headers["Authorization"] = `Bearer ${accessToken}`; // 액세스 토큰이 있으면 헤더에 추가합니다. config.withCredentials = true; } @@ -23,5 +23,29 @@ instance.interceptors.request.use( }, (error) => { return Promise.reject(error); - }, -); \ No newline at end of file + } +); + +// 응답 인터셉터 추가 +instance.interceptors.response.use( + (response) => response, + (error) => { + if (error.response) { + if (error.response.status === 404) { + console.log("404 error: Page not found"); + window.location.href = "/error"; + } + const errorCode = error.response.data?.errorCode; + if (errorCode === "USER_LOCATION_002") { + console.log( + "USER_LOCATION_002: 사용자와 명소 정보가 일치하지 않습니다." + ); + window.location.href = "/error"; + } + } else if (error.code === "ECONNABORTED") { + console.log("Request timeout"); + window.location.href = "/error"; + } + return Promise.reject(error); + } +); diff --git a/src/pages/CompletePage/styled.js b/src/pages/CompletePage/styled.js index e53b78f..46e66ba 100644 --- a/src/pages/CompletePage/styled.js +++ b/src/pages/CompletePage/styled.js @@ -66,4 +66,5 @@ export const Button = styled.div` font-style: normal; font-weight: 600; color: #fef7e2; + cursor: pointer; `;