Browse Source

네트워크 error 예외처리

master
김장현 4 months ago
parent
commit
87cc4f186f
  1. 4
      src/components/message/MessageModal.js
  2. 5
      src/redux/features/account/auth/authThunk.ts
  3. 19
      src/router/hoc/authenticationCheck.tsx

4
src/components/message/MessageModal.js

@ -8,6 +8,7 @@ import {
} from '@component/ui'; } from '@component/ui';
import { useHistory } from 'react-router-dom'; import { useHistory } from 'react-router-dom';
import { closeModal } from '@src/redux/features/comn/message/messageSlice'; import { closeModal } from '@src/redux/features/comn/message/messageSlice';
import { ERROR_MESSAGE } from '@src/configs/msgConst';
export const MessageModal = () => { export const MessageModal = () => {
const dispatch = useDispatch(); const dispatch = useDispatch();
@ -17,6 +18,9 @@ export const MessageModal = () => {
); );
const handlerClose = () => { const handlerClose = () => {
if (body === ERROR_MESSAGE) {
history.replace('/account/login');
}
dispatch(closeModal()); dispatch(closeModal());
if (isHistoryBack) { if (isHistoryBack) {

5
src/redux/features/account/auth/authThunk.ts

@ -55,11 +55,10 @@ export const setLogin = createAsyncThunk(
} catch (error: any) { } catch (error: any) {
thunkAPI.dispatch( thunkAPI.dispatch(
openModal({ openModal({
header: '로그인 실패', header: ERROR_TITLE,
body: error body: ERROR_MESSAGE
}) })
); );
return thunkAPI.rejectWithValue(error);
} }
} }
); );

19
src/router/hoc/authenticationCheck.tsx

@ -4,6 +4,13 @@ import { useSelector, useDispatch } from '@src/redux/store';
import { checkToken } from '@src/redux/features/account/auth/authThunk'; import { checkToken } from '@src/redux/features/account/auth/authThunk';
import { ICheckAuthencationRs } from '@src/redux/features/account/auth/authState'; import { ICheckAuthencationRs } from '@src/redux/features/account/auth/authState';
import { clientDispatchTopMenu } from '@src/redux/features/layout/layoutSlice'; import { clientDispatchTopMenu } from '@src/redux/features/layout/layoutSlice';
import { openModal } from '@src/redux/features/comn/message/messageSlice';
import {
COOKIE_ACCESS_TOKEN,
COOKIE_REFRESH_TOKEN,
cookieStorage
} from '@src/utility/authService/cookie';
import { ERROR_TITLE, ERROR_MESSAGE } from '@src/configs/msgConst';
interface IOption { interface IOption {
authRoute?: boolean; authRoute?: boolean;
@ -24,12 +31,16 @@ export default function (SpecificComponent: ReactNode, option: IOption) {
) => JSX.Element; ) => JSX.Element;
useEffect(() => { useEffect(() => {
dispatch(checkToken() as any).then(({ payload: { result } }) => { if (props.match.path === '/account/login') {
setIsRender(true);
return;
}
dispatch(checkToken() as any).then(({ payload }) => {
try { try {
// 로그인 해야만 접근 가능한 페이지인지 체크하는 옵션 // 로그인 해야만 접근 가능한 페이지인지 체크하는 옵션
const { authRoute } = option; const { authRoute } = option;
if (!result) { if (!payload?.result) {
if (authRoute) { if (authRoute) {
props.history.replace('/account/login'); props.history.replace('/account/login');
return; return;
@ -42,9 +53,7 @@ export default function (SpecificComponent: ReactNode, option: IOption) {
} }
} }
setIsRender(true); setIsRender(true);
} catch (error) { } catch (error) {}
// props.history.replace('/account/login');
}
}); });
return () => { return () => {
setIsRender(false); setIsRender(false);

Loading…
Cancel
Save