fetch() promise는 HTTP error에 의해 reject 되지 않는다.
https://developer.mozilla.org/en-US/docs/Web/API/fetch
fetch(api url)
.then(( response ) => {
if(!response.ok) {
throw new Error(`error status: ${response.status}`)
}
return response.json()
})
.then(( data ) => {
// 처리 코드
console.log(data)
})
.catch((error) => {
// 에러 처리 코드
console.log(error)
})
'NOTE' 카테고리의 다른 글
자바스크립트 sort()로직 (0) | 2023.04.15 |
---|---|
매개변수, 인자, 인수 (0) | 2023.04.05 |
gh-pages을 이용하여 Github Pages에 배포하기 (0) | 2023.03.15 |
parseInt(), Number() 의 차이 (0) | 2023.03.02 |
Array.findIndex() (0) | 2023.03.02 |