I have two applications running at the same time. The first one is fetching APIs from vessel-finder and finding only a specific number of boats. The second application is the user interface used to visualize data from the fetch, specifically latitude and longitude of boats.
The problem I have is that the fetch seems to arrive correctly to the end point but that throws an error of TypeError: data is not iterable as also shown here on the terminal.
It seems that the problem might be the API fetch. Below the code I am using for that:
router.get('/hello', async function(req, res, next) {
try {
const { data } = await axios.get(
'https://api.vesselfinder.com/vesselslist?userkey=KEY'
);
const [ metaData, ships ] = data;
console.log(data);
res.send(data);
} catch (error) {
res.send(error);
console.log(error);
}
});
module.exports = router;
While investigating what the problem might be, I came across this source which also uses axios to get the call to the API.
I wonder now if the fetch I am making is basically incomplete and because of that, data is not iterable...
Also from this post I was able to handle a missing Promise using a try-catch block that was preventing me from compiling.
Is the problem due to a missing axios.get('API call').then.setState instruction I am missing?, if so how could I fix that?
Thank you very much for pointing to the right direction for solving this problem.
const [metaData, ships] = dataon it. Open the network tab of your developer toolbar and inspect the response of your endpoint. It is probably not a list.datato the console? What does it show? I probably is not what you think.console.log(data + 'This is the error')and this is the result of the terminal. Is that telling you something?