I'm fetching data from an external API and I get the following error on some of the endpoints:
reason: getaddrinfo EAI_AGAIN [the url]:443
I can only assume that the owner of the API has a rate limiter of some sort and since all the fetching is done at once some URLs get blocked.
So I'm trying to put a delay between each fetch, but with no luck. Here is my try:
class someClass {
...
dealyedFetch(url) {
return new Promise ((resolve, reject) => {
setTimeout(() => {
fetch(url, (err, res) => {
if (err) return reject(err)
return resolve(res)
})
}, 5000)
})
}
fetchUrls() {
return Promise.all(
this.urlList.map(url => {
return this.dealyedFetch(url)
.then(/* macht krieg */)
.catch(err => ({err, url}))
})
)
}
}
the above doesn't work and it seems to fire all the fetching at once. Please illuminate me.