How to write an if statement for fetch('link'). So that when one fetch('link1') takes more than 3 seconds to respond then, timeout the link1 use the other fetch('link2')
if ()
{
fetch('https://api.apilayer.com/exchangerates_data/latest?base=USD', requestOptions)
.then(response => response.json())
.catch(error => {
console.log('Error', error);
});
return false;
} else
{
fetch("https://api.apilayer.com/fixer/latest?base=USD", requestOptions)
.then(response => response.json())
.catch(error => {
console.log('Error', error);
});
return false;
}
I have tried the above code but doesn't work..