Now Printing Money

    @octokit/plugin-retry
    TypeScript icon, indicating that this package has built-in type declarations

    4.0.3 • Public • Published

    plugin-retry.js

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

    @latest Build Status

    Usage

    Browsers

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

    <script type="module">
      import { Octokit } from "https://cdn.skypack.dev/@octokit/core";
      import { retry } from "https://cdn.skypack.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");
    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 }}. Note that the doNotRetry option from the constructor is ignored in this case, requests will be retried no matter their response code.

    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

    Keywords

    none

    Install

    npm i @octokit/plugin-retry

    DownloadsWeekly Downloads

    285,352

    Version

    4.0.3

    License

    MIT

    Unpacked Size

    22 kB

    Total Files

    15

    Last publish

    Collaborators

    • kfcampbell
    • nickfloyd
    • gr2m
    • octokitbot