I'm really frustrated for not figuring out how to handle the error. I've tried many methods on the internet like the try catch one, and .catch, but nothing worked. I'm just trying to handle an error that will occur in an async function. The last method I tried was this one:
async function getData(key) {
data = await fetch(key);
data = await data.json()
alert('done');
}
async function checkData(key) {
try{
await getData(key)
} catch(err) {
alert('error')
}
In the end, all I want is to notify the user about the error with alert and also not show that error in the console (Like it does without the handling). And by error, I mean errors that comes back from the server like a 404 Not Found or a Bad Request.
fetchdoes not throw depending on the status of responses received from the server. I believe it only throws for a network error. Check documentation for how to determine if a request failed.