Skip to content

Add option for request retries #132

@gr2m

Description

@gr2m

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions