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

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

@ -55,11 +55,10 @@ export const setLogin = createAsyncThunk(
} catch (error: any) {
thunkAPI.dispatch(
openModal({
header: '로그인 실패',
body: error
header: ERROR_TITLE,
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 { ICheckAuthencationRs } from '@src/redux/features/account/auth/authState';
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 {
authRoute?: boolean;
@ -24,12 +31,16 @@ export default function (SpecificComponent: ReactNode, option: IOption) {
) => JSX.Element;
useEffect(() => {
dispatch(checkToken() as any).then(({ payload: { result } }) => {
if (props.match.path === '/account/login') {
setIsRender(true);
return;
}
dispatch(checkToken() as any).then(({ payload }) => {
try {
// 로그인 해야만 접근 가능한 페이지인지 체크하는 옵션
const { authRoute } = option;
if (!result) {
if (!payload?.result) {
if (authRoute) {
props.history.replace('/account/login');
return;
@ -42,9 +53,7 @@ export default function (SpecificComponent: ReactNode, option: IOption) {
}
}
setIsRender(true);
} catch (error) {
// props.history.replace('/account/login');
}
} catch (error) {}
});
return () => {
setIsRender(false);

Loading…
Cancel
Save