@octokit/plugin-retry
Automatic retry plugin for octokit
Last updated 16 days ago by gr2m .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @octokit/plugin-retry 
SYNC missed versions from official npm registry.

plugin-retry.js

Retries requests for server 4xx/5xx responses except 400, 401, 403 and 404.

@latest Build Status

Usage

Browsers

Load @octokit/plugin-retry and @octokit/core (or core-compatible module) directly from cdn.pika.dev

<script type="module">
  import { Octokit } from "https://cdn.pika.dev/@octokit/core";
  import { retry } from "https://cdn.pika.dev/@octokit/plugin-retry";
</script>
Node

Install with npm install @octokit/core @octokit/plugin-retry. Optionally replace @octokit/core with a core-compatible module

const { Octokit } = require("@octokit/core");
const { retry } = require("@octokit/plugin-retry");

Note: If you use it with @octokit/rest v16, install @octokit/core as a devDependency. This is only temporary and will no longer be necessary with @octokit/rest v17.

const MyOctokit = Octokit.plugin(retry);
const octokit = new MyOctokit({ auth: "secret123" });

// retries request up to 3 times in case of a 500 response
octokit.request("/").catch((error) => {
  if (error.request.request.retryCount) {
    console.log(
      `request failed after ${error.request.request.retryCount} retries`
    );
  }

  console.error(error);
});

To override the default doNotRetry list:

const octokit = new MyOctokit({
  auth: "secret123",
  retry: {
    doNotRetry: [
      /* List of HTTP 4xx/5xx status codes */
    ],
  },
});

To override the number of retries:

const octokit = new MyOctokit({
  auth: "secret123",
  request: { retries: 1 },
});

You can manually ask for retries for any request by passing { request: { retries: numRetries, retryAfter: delayInSeconds }}

octokit
  .request("/", { request: { retries: 1, retryAfter: 1 } })
  .catch((error) => {
    if (error.request.request.retryCount) {
      console.log(
        `request failed after ${error.request.request.retryCount} retries`
      );
    }

    console.error(error);
  });

Pass { retry: { enabled: false } } to disable this plugin.

Contributing

See CONTRIBUTING.md

License

MIT

Current Tags

  • 3.0.2                                ...           latest (16 days ago)

9 Versions

  • 3.0.2                                ...           16 days ago
  • 3.0.1                                ...           5 months ago
  • 3.0.0                                ...           5 months ago
  • 2.2.0                                ...           a year ago
  • 2.1.2                                ...           a year ago
  • 2.1.1                                ...           a year ago
  • 2.1.0                                ...           a year ago
  • 2.0.0                                ...           a year ago
  • 1.0.0                                ...           a year ago

Copyright 2014 - 2016 © taobao.org |