diff --git a/src/pages/LoginEntrance/components/HostComponent.tsx b/src/pages/LoginEntrance/components/HostComponent.tsx index 51b59bc5..c1d5ea08 100644 --- a/src/pages/LoginEntrance/components/HostComponent.tsx +++ b/src/pages/LoginEntrance/components/HostComponent.tsx @@ -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; @@ -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 ( <>