Open Zunaidali opened 1 month ago
Modify your code to handle the 404 error gracefully and provide feedback in the UI.
async function updateExchangeRate() {
try {
const response = await fetch('https://cdn.jsdelivr.net/gh/fawazahmed0/currency-api@1/latest/currencies/usd/inr.json');
if (!response.ok) {
throw new Error(HTTP error! status: ${response.status}
);
}
const data = await response.json();
console.log('Exchange rate:', data);
} catch (error) {
console.error('Error fetching exchange rate:', error);
alert("Could not fetch exchange rate. Please try again later.");
}
}
If the above URL is outdated, consider using a different currency API like ExchangeRate-API or Open Exchange Rates and update the URL in your code accordingly.
app.js:36
updateExchangeRate @ app.js:36 (anonymous) @ app.js:58 load (anonymous) @ app.js:57Understand this error VM3742:1 Uncaught (in promise) SyntaxError: Unexpected token 'F', "Failed to "... is not valid JSON
this error show