ENHANCEMENT: Some way to add different url sources?
federicosan opened this issue · 1 comments
I am integrating payments for a site and I need to fetch the dollar price for ARS, I need this to make the payment. I am fetching this from a national bank's API but it sometimes fails so I made my own fetch retry, and then started researching for it. I am used to making bots so I need a fault-tolerant fetch, a fetch that will always give you what you need, maybe by providing different source APIs, it would retry or switch until it gets a useful result. I am still trying to understand your code, it seems you are using some knowledge on how fetch retries by itself? I can't see the code looping or increasing attempts.
Maybe this could be handled in a fetch-alt
bundle instead? It could wrap this bundle and if this bundle fails with its retry-strategies the fetch-alt
bundle tries the next (randomised) url?
export default function fetch(fetch) {
return function(urls: string[], isFail: (response: Response) => boolean, options) {
return urls.reduce(function(result, url) {
return result.then(isFail)
}, Promise.resolve())
}
}
const fetch = require("fetch-alt")("@vercel/fetch-retry")("node-fetch")
fetch([url1,url2,url3], function isFail(response) {
return response.status === 418
})