์ค๋์ ์ฝ๋์ ๋ถํธ์บ ํ์์ ๋ฐฐ์ด fetch,ํ๋ก๋ฏธ์ค์ ๋ํ ๋์ ์ง์์ ์ํํ ์ ์์๋ค.
๋๋ 404 ์๋ต์ด๋ฉด ๋น์ฐํ ๋ฆฌํด๋๋ ํ๋ก๋ฏธ์ค ๊ฐ์ฒด๊ฐ rejected์ํ๊ฐ ๋ ์ค ์์๋ค. ํ์ง๋ง ์๋์๋ค.
https://stackoverflow.com/questions/39297345/fetch-resolves-even-if-404
404,500๋ ํ๋ก๋ฏธ์ค ๊ด์ ์์ ์ฑ๊ณต์ ์ธ ์์ฒญ์ด๋ผ๊ณ ํ๋ค.. ์ด๋ฐ ์ค๋ ๋ชจ๋ฅด๊ณ '๋์ฒด ์ catch๊ฐ ์คํ๋์ง ์์ง?' ๋ผ๋ ์๊ฐ๋ง ๋ช ๋ฒ์ ๋ค์๋ค.
fetch("https://bootcamp-api.codeit.kr/api/check-emailaaa", {
headers: {
"Content-Type": "application/json",
},
method: "POST",
body: JSON.stringify({ email: email.value }),
})
.then((res) => {
if(!res.ok){
if(res.status === 404){
throw new Error('');
}
}
res.json();
})
//์๋ต
.catch()
๋ฐ๋ผ์ ๋ฐ๋ก ์๋ฌ์ฒ๋ฆฌ๋ฅผ ํ๊ณ ์ถ๋ค๋ฉด ์๊ฐ์ด 404๋ฅผ ๋ง๋ฌ์๋ ์๋ฌ๋ฅผ ๋ฐ์์์ผ์ผ ํ๋ค.
์๋ ์ฑ์งํผํฐ๊ฐ ๋์๊ฒ ๊ตฌ๋ผ๋ฅผ ์น ๋ด์ฉ์ด๋ค.. ์์ค..