-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
✨ Feature: 에러페이지 연결
- Loading branch information
Showing
2 changed files
with
32 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,51 @@ | ||
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; | ||
} | ||
|
||
return config; | ||
}, | ||
(error) => { | ||
return Promise.reject(error); | ||
}, | ||
); | ||
} | ||
); | ||
|
||
// 응답 인터셉터 추가 | ||
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); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,4 +66,5 @@ export const Button = styled.div` | |
font-style: normal; | ||
font-weight: 600; | ||
color: #fef7e2; | ||
cursor: pointer; | ||
`; |