const getWeather = () => {
fetch('http://localhost:3000/api/v1/weather?location=' + weatherLocation.value)
.then(res => {
if (res.ok) return res.json();
else throw new Error(res.status + ' (' + res.statusText + ')');
})
.catch(err => {
console.log('[SERVER] Could not get weather information');
console.log(err);
})
.then(data => updateWeather(data.data))
.catch(err => console.log(err));
};
The last .then()
function should not run if the first .catch()
function catched an error?
As of right now, the data
parameter in the last.then()
function is undefined
because the request failed. The second .catch()
does catch that error but it should have never run in the first place.
How can I do this?