Skip to content

Commit

Permalink
feat : 토큰 만료 예외 코드 처리 (#225)
Browse files Browse the repository at this point in the history
  • Loading branch information
hyesung99 authored Dec 1, 2023
1 parent 3df82d4 commit c3b01bb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
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 };

0 comments on commit c3b01bb

Please sign in to comment.