The console log is fine for development but once in production, I need to be able to handle the situation and not just hang.
return fetch(url, {method: 'get'})
.then(response => response.json())
.catch(err => console.log(err));
}
Handle the error in .catch() instead of just displaying a message in the log.
.catch(err => {
console.log(err);
// do your error handling here
});
I know it’s still just console log in the code snippet but I have tried that and that .catch is not .catching it.
This:
try {
return fetch(url, {method: 'get'})
.then(response => response.json())
.catch(err => console.log(".catch err: " + err));
} catch (err) {
console.log("try .catch err: " + err)
}
Still results in this;
The snippet above is from my backend code. Apparently you have to .catch it from the front end code. I think I’m good now.