Upon running the code snippet below, I noticed that the terminal outputs "function called" and "end function", but skips over the intermediate console.log(). It seems like the request is not being executed properly. Any ideas why this might be happening?
export const retrieveData : Function = () => {
console.log('function called');
const url = `https://www.alphavantage.co/query?function=FX_DAILY&from_symbol=EUR&to_symbol=USD&apikey=${key}`;
axios.get(url,{
responseType: 'json',
headers: { 'User-Agent': 'request' }
})
.then(response => {
console.log('first step', response);
// return response.json();
return response;
})
.then(data => {
console.log('second step');
console.log(data)
return 'hola'
} )
.then(successMessage => {
console.log('success',successMessage);
})
.catch(error => console.error(`Error: ${error}`));
console.log('end function');
};
I've tested the same URL and key in Postman, and there were no issues with the endpoint. Everything worked perfectly.