=> {
if (name){
const apiLink = `https://restcountries.com/v3.1/name/${name}?fullText=true`;
axios
.get(apiLink)
.then(response => {
setCountry(response.data[0]);
})
.catch(()=> {
setCountry(null)
});
}
}, [name])
It works smoothly except in the cases where the country does not exist. Even then it does not break but it logs the 404 error to the console, which I heard looks unprofessional.
Is there a need to a remedy? If so, what is it
I often see tons of console errors on big websites so I dont think so. But if you want to hide it I think you can just pass the error into the catch block .catch( err => { setCountry(null) });
Is this different than: .catch(err => setCountry(null));
I actually even used console.log as a solution, but then it just doubled the log
looks like it isnt possible https://stackoverflow.com/a/52807512
Oh okay, great. Thanks for your time
Обсуждают сегодня