So, I’ve got some code like this:
async function test() {
try {
const response = await fetch(url);
return response;
} catch (e) {
console.log('caught');
console.dir(e);
}
return;
}
What I’ve noticed, is that if fetch() rejects immediately (synchronously?), i.e., if the internet is down, then the catch block does not run. However, if it’s a rejection that takes a while, say, unable to resolve host name error, then the catch block will run. Does anyone know why this is? I eventually had to change to just using .catch() to catch all errors (including internet being down).