Skip to content

Commit

Permalink
feat: 인증 관련 오류 발생시 로그아웃
Browse files Browse the repository at this point in the history
  • Loading branch information
guridaek committed Oct 8, 2023
1 parent 8ffc1d3 commit f322486
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions frontend/src/apis/error.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { ACCESS_TOKEN_LOCAL_STORAGE_KEY } from '@/constants';
import { ERROR_DESCRIPTION, ERROR_TITLE } from '@/constants/message';
import { APIError, CustomApiError } from '@/types/error';

const removeAccessToken = () => localStorage.removeItem(ACCESS_TOKEN_LOCAL_STORAGE_KEY);
import { logout } from './auth';

export const validateResponse = async (response: Response) => {
if (response.ok) return;
Expand All @@ -11,14 +9,9 @@ export const validateResponse = async (response: Response) => {
const apiError: APIError = await response.json();

if (apiError.errorCode.includes('JW') || apiError.errorCode.includes('OA')) {
removeAccessToken();
window.location.reload();
logout();

const authErrorCode = ['JW007', 'JW008', 'JW009', 'JW010'];
throw new CustomApiError(
ERROR_TITLE.NO_PERMISSION,
authErrorCode.includes(apiError.errorCode) ? ERROR_DESCRIPTION.TOKEN_EXPIRATION : ERROR_DESCRIPTION.NO_TOKEN,
);
throw new CustomApiError(ERROR_TITLE.NO_PERMISSION, ERROR_DESCRIPTION.NO_TOKEN);
}
} catch (error) {
throw new CustomApiError(ERROR_TITLE.REQUEST, `${response.status}: ` + ERROR_DESCRIPTION.UNEXPECTED);
Expand Down

0 comments on commit f322486

Please sign in to comment.