Skip to content

Commit

Permalink
fix: 403error, 400error 처리
Browse files Browse the repository at this point in the history
  • Loading branch information
ljh0608 committed Oct 11, 2023
1 parent 134f82d commit b4ef35c
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions src/pages/LoginEntrance/components/HostComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import React, { Dispatch, SetStateAction, useState } from 'react';
import axios,{ AxiosError } from 'axios';
import { useNavigate, useParams } from 'react-router-dom';

import axios from 'axios';
import Button from 'components/atomComponents/Button';
import Header from 'components/moleculesComponents/Header';
import IncorrectInfoModal from './IncorrectInfoModal';
import NoAvailableTimeModal from './NoAvailableTimeModal';
import PasswordInput from 'components/atomComponents/PasswordInput';
import Text from 'components/atomComponents/Text';
import TextInput from 'components/atomComponents/TextInput';
import Header from 'components/moleculesComponents/Header';
import TitleComponent from 'components/moleculesComponents/TitleComponents';
import { client } from 'utils/apis/axios';
import { useNavigate, useParams } from 'react-router-dom';
import styled from 'styled-components/macro';
import { theme } from 'styles/theme';
import { client } from 'utils/apis/axios';

import IncorrectInfoModal from './IncorrectInfoModal';
import NoAvailableTimeModal from './NoAvailableTimeModal';

interface HostInfoProps {
name: string;
Expand Down Expand Up @@ -60,24 +61,29 @@ function HostComponent({ hostInfo, setHostInfo }: HostProps) {
} else {
console.log(data.message);
}
} catch (e) {
} catch (err) {
//현재 err는 객체를 보내주지 않아서 다른 에러도 이 로직이 실행될 문제가 있음

if (axios.isAxiosError(e)) {
// // axios에서 발생한 error
// console.log(err.response);
// }
// const err = e as AxiosError;
const err= e;
if (err.response?.status === 403) {
console.log(err.response.data?.message);
setIsModalOpen(true);
} else {
console.log(err.response?.status);
console.log(err.response?.data.message);
}
}
if (axios.isAxiosError(err)) {
// // axios에서 발생한 error
// console.log(err.response);
// }
// const err = e as AxiosError;
if (err.response) {
//타입 가드 사용
if (err.response.status === 403) {
console.log(err.response.data.message);
setIsModalOpen(true);
} else if (err.response.status === 400) {
setIsLoginModalOpen(true);
} else {
console.log(err.response.status);
console.log(err.response.data.message);
navigate('/error');
}
}
}
}
};
return (
<>
Expand Down

0 comments on commit b4ef35c

Please sign in to comment.