Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

ENHANCEMENT: Some way to add different url sources? #16

Open
federicosan opened this issue Aug 16, 2019 · 1 comment
Open

ENHANCEMENT: Some way to add different url sources? #16

federicosan opened this issue Aug 16, 2019 · 1 comment

Comments

@federicosan
Copy link

federicosan commented Aug 16, 2019

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.

@pke
Copy link

pke commented Sep 18, 2021

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
})

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants