Hello StackOverflow Community,
I am working on a project where I am fetching data. If the fetch fails, I should alert the user of that.
Here is the example block of code:
async function showStackOverflow(){
try{
fetch('urlexample', {
method:'GET',
headers:
{
"Content-Type" : "///",
'Authorization': `///`,
}})
.then(response => response.json())
.then(data => console.log(data));
}
.catch((error) => {
alert("Reauthenticate")
})
};
When I create this block of code, it complains that I don't have a try statement. Any help appreciated.