Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#154] axios instance 액세스 토큰 만료 외의 인증 에러 처리 추가 #156

Merged
merged 2 commits into from
Jan 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/api/lib/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ const onResponse = (response: AxiosResponse): AxiosResponse => {
const onErrorResponse = async (error: AxiosResponseError<string>) => {
const { config, response } = error;

// 액세스 토큰이 만료되었을 때
if (response && response.status === 401) {
// 액세스 토큰이 만료되었을 때
if (error.response.data.code === 'JWT_EXPIRED_AUTHORIZATION') {
const originalRequest = config;

Expand Down Expand Up @@ -69,12 +69,21 @@ const onErrorResponse = async (error: AxiosResponseError<string>) => {
deleteAllCookies();
window.location.replace('/login');
}
} else {
// 액세스 토큰이 만료 이외의 모든 인증 에러 처리
console.log(error.response.data.code, error.response);
alert('서버에서 인증 오류가 발생했습니다.\n다시 로그인해주세요.');
await postLogout();
deleteAllCookies();
window.location.replace('/login');
}
} else {
console.log(error.response.data.code, error.response);
return Promise.reject(error);
alert('서버에서 인증 오류가 발생했습니다.\n다시 로그인해주세요.');
await postLogout();
deleteAllCookies();
window.location.replace('/login');
}
console.log('response error : ', error);
return Promise.reject(error);
};

// 요청 인터셉터 추가
Expand Down