I've been looking for this over and over but cant find the proper answer
Using Fetch, in order to throw errors when getting status other than ok we must do it manually. The back end is providing with an specific message about the error along the 401,404 etc, error code. I want to access to it on my fetch but dont know how.
.then((response) => {
if (response.ok) {
return response.text();
}
else {
throw new Error(response.text()); ///THIS DOES NOT WORK.
}
})
.then(result => alert ("Added Successfully"))
.catch(error =>alert (error.message)); ///AND OF COURSE NEITHER DOES THIS.
console.log(error)to see how the error looks like first, then you can specify the properties you want to access directly