Reputation: 10304
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
Reputation: 5107
It's also possible for fetch
to throw an AbortError
. See the documentation for more details
Upvotes: 1