Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option for request retries #132

Closed
gr2m opened this issue Aug 1, 2019 · 0 comments
Closed

Add option for request retries #132

gr2m opened this issue Aug 1, 2019 · 0 comments

Comments

@gr2m
Copy link

gr2m commented Aug 1, 2019

I'm using this library to de-reference a JSON API spec with hundreds of references.

await jsonSchemaRefParser.dereference(
  "https://raw.githubusercontent.com/octokit/routes/v21.0.4/openapi/api.github.com/index.json"
);

I see random request errors which I could workaround quite easily by adding a simple retry feature in lib/resolvers/http.js

-    req.on("error", reject)
+    let retries = 3
+    req.on("error", error => {
+      if (!--retries) {
+        return reject(error);
+      }
+
+      console.log(`retrying GET ${u.href} (${3 - retries}/3)`);
+
+      return get(u, httpOptions).then(resolve, reject);
+    });

Instead of hardcoding it, it would be simple enough to add an option such as resolve.http.retries.

Would you accept a PR to add such an option?

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

Successfully merging a pull request may close this issue.

2 participants