I am building a react js website where I have to call a currency converter API. Calling that API works perfectly when served locally (on localhost), but once I deploy it to Netlify, it fails from working.
ConvertCurrency = async (from, to, amount) => {
let endpoint = 'xxxxxx';
let access_key = "xxxxxxxxxxxx";
const url = 'http://data.fixer.io/api/' + endpoint + '?access_key=' + access_key + '&from=' + from + '&to=' + to + '&amount=' + amount;
try {
const res = await Axios.get(url)
const rate = Math.round(((res.data.info.rate* 100) / 100)).toFixed(2)
return rate;
} catch (err) {
console.log(err)
}
return -1;
}
This is the error that I am catching(in the try{}catch(){} exception).
Error: Network Error
at e.exports (createError.js:17)
at XMLHttpRequest.p.onerror (xhr.js:83)
Any help is appreciated.
Thanks