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

SKRF-465 feat : 토큰 만료 예외 코드 처리 #225

Merged
merged 1 commit into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions src/apis/interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ const handleTokenError = async (error: AxiosError<HttpException>) => {

originalRequest.headers.Authorization = `Bearer ${refreshToken}`;

if (error.response?.data.code === EXCEPTION_CODE.INVALID_ACCESS_TOKEN) {
if (error.response?.data.code === EXCEPTION_CODE.EXPIRED_ACCESS_TOKEN) {
return axiosClientWithAuth(originalRequest);
}

return Promise.reject(error);
};

const handleRefreshTokenError = (error: AxiosError<HttpException>) => {
if (error.response?.data.code === EXCEPTION_CODE.INVALID_REFRESH_TOKEN) {
if (error.response?.data.code === EXCEPTION_CODE.EXPIRED_REFRESH_TOKEN) {
alert('로그인이 만료되었습니다. 다시 로그인해주세요.');
window.location.href = PATH.LOGIN;
}
Expand Down
4 changes: 4 additions & 0 deletions src/constants/exceptionCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ const EXCEPTION_CODE = {
BAD_WORD_DETECTED: 'BAD_WORD_DETECTED',
EXISTED_FORM: 'EXISTED_FORM',
USER_CANNOT_WITHDRAW: 'USER_CANNOT_WITHDRAW',
EXPIRED_ACCESS_TOKEN: 'EXPIRED_ACCESS_TOKEN',
EXPIRED_REFRESH_TOKEN: 'EXPIRED_REFRESH_TOKEN',
} as const;

const EXCEPTION_CODE_MESSAGE: ExceptionCodeMessage = {
Expand Down Expand Up @@ -68,6 +70,8 @@ const EXCEPTION_CODE_MESSAGE: ExceptionCodeMessage = {
BAD_WORD_DETECTED: '비속어가 포함되어 있습니다.',
EXISTED_FORM: '이미 폼 옵션을 설정한 행사입니다.',
USER_CANNOT_WITHDRAW: '소속된 클럽을 모두 나간 뒤 탈퇴할 수 있습니다.',
EXPIRED_ACCESS_TOKEN: '만료된 토큰입니다.',
EXPIRED_REFRESH_TOKEN: '만료된 리프레시 토큰입니다.',
};

export { EXCEPTION_CODE, EXCEPTION_CODE_MESSAGE };
Loading