I am using fetch and it is to my understanding that 404 codes should happen but not GET 404 errors when fetching from a non existent page. I am using the open weather map api. The error that I'm getting is GET ${forcastUrl} 404 (Not Found).
My fetch statement looks like this:
function fetchingForcast(forcastUrl){
fetch(forcastUrl)
.then(validateWeatherResponse)
.then(responseToJSON)
.then(dat => {
forcastDat = dat;
updateforcastPanel();
})
.catch(error=>{
console.log(error);
})
}
function validateWeatherResponse(response){
if (response.ok){
return response;
} else {
throw Error("response.ok: "+ response.ok);
}
validateWeatherResponse checks if the response is ok and if not, it throws an error. However, when it does throw an error, it should go to catch and console.log the error. When I use the debug devtool on chrome, the error appears to happen as soon as validateWeatherResponse is called.
Besides for this error, my code works when I input a correct website. It is to my understanding that 404 errors should not occur so I'd like to understand why this is happening. Thanks!