shradha-khapra / JavaScriptSeries

257 stars 214 forks source link

Currency Converter #34

Open Zunaidali opened 1 month ago

Zunaidali commented 1 month ago

app.js:36

   GET https://cdn.jsdelivr.net/gh/fawazahmed0/currency-api@1/latest/currencies/usd/inr.json 404 (Not Found)

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

AadiSharma49 commented 3 weeks 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."); } }

AadiSharma49 commented 3 weeks ago

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.