'Ho to make 404 error alert in axios react
Hello how can realize 404 error in axios? Here's my code
const WeatherFunc = async (city) => {
const { data } = await axios.get(url, {
params: {
q: city,
units: 'metric',
APPID: apikey,
}
});
return data;
}
Solution 1:[1]
Check the response status in the axios promise
axios.get(url, {
//...
}).then(response => {
if (response.status === 404) {
// handle your 404
}
// ...
}).catch(error => {
// handle server error..
})
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Peterrabbit |
