Suppose, I have this function with a wrong 'uri' string provided to fetch:
function imgChanger(uri) {
fetch('uri', { mode: 'cors' })//WRONG 'uri' to demonstrate that catch doesn't prevent console's red error
.then(function (response) {
if (!response.ok) {
throw new Error(response.statusText);
}
return response.json();
}).then(function (response) {
img.src = response.data.images.original.url;
}).catch((err)=>{
console.log(err);
});
}
Despite handling the error, I can see a 404 message in the console:
I have two questions regarding this: why is it being shown despite catching it and how do I handle it?

Aucun commentaire:
Enregistrer un commentaire