Tal Avissar
Tal Avissar

Reputation: 10304

Does fetch only throws TypeError

Can I assume that fetch can only throw errors of TypeError?

const request = async () => {
    let response = null;
    try {
     response = await fetch('https://api.com/values/1');
    } catch (err){
      //is the err here is always of type typeError
    }
    if(!response.ok){
      //bla bla bla 401/403 ...
    }
    const json = await response.json();
    console.log(json);
}

request();

Upvotes: 1

Views: 139

Answers (1)

Hamms
Hamms

Reputation: 5107

It's also possible for fetch to throw an AbortError. See the documentation for more details

Upvotes: 1

Related Questions