7.1.2 • Published 7 months ago

@octokit/plugin-retry v7.1.2

Weekly downloads
49,005
License
MIT
Repository
github
Last release
7 months ago

plugin-retry.js

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

@latest Build Status

Usage

Load @octokit/plugin-retry and @octokit/core (or core-compatible module) directly from esm.sh

<script type="module">
  import { Octokit } from "https://esm.sh/@octokit/core";
  import { retry } from "https://esm.sh/@octokit/plugin-retry";
</script>

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

import { Octokit } from "@octokit/core";
import { retry } from "@octokit/plugin-retry";

!IMPORTANT As we use conditional exports, you will need to adapt your tsconfig.json by setting "moduleResolution": "node16", "module": "node16".

See the TypeScript docs on package.json "exports". See this helpful guide on transitioning to ESM from @sindresorhus

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

@everything-registry/sub-chunk-676vstest-oct1@codefresh-io/cf-git-providersk8s-deploy-actiongh-org-scantypescript-github-action-templatetoken-who-am-itoken-who-am-i-action@artsy/dupe-report@auto-canary/core@auto-it/core@binarymuse/probot@carbon/cli@chancethedev/cli@achingbrain/semantic-release-github@actions/artifact@actions/attest@667/ghost-storage-github@jupiterone/graph-github@cloudnativetoolkit/git-client@denizhoxha/probot@deviavir/actions-common-scansupdate-existing-releaseupdate-my-badgesupload_github_release_assets_action@favware/cliff-jumper@grept/core@grept/octokit@hickorytechnology/semantic-release-github@gr2m/semantic-release-github-487@georgexu99/publisher-github@gistbase/gistbase@gitops-toolbox/github-tools@infracost/compost@infinitebrahmanuniverse/nolb-_oc@mahnunchik/publisher-github@nerdwallet/shepherd@electron-forge/publisher-github@elastic/github-checks-reporter@mmomtchev/node-pre-gyp-github@mbcrm/cli@intuit-auto/core@johnlindquist/kit@keyrxng/ubiquity-os-kernel@octoherd/octokit@pkgjs/statusboard@probot-ng/core@redpanda-data/docs-extensions-and-macros@skynet1024/probot@restfulhead/auto-it-core@semantic-release/github@servicenow/climutate-github-repositories-climongodb-backup-cloudpackage-adoptionoctokitoctotaskscriptkit-octokitnode-package-release-actionnoriprobotpurescript-spaghettosimple-octokitsnyk-api-importgithub-release-writergithub-repo-toolsgithub-org-reporterghost-storage-githubghost-storage-github-forkgood-samaritanhexo-generator-issuesmaintserv@stead/cli@swsdk/github@ubq-mentlegen/plugin-sdk@unitednations/cli@ubiquity-os/plugin-sdk@ubiquity-os/ubiquity-os-kernel@un/cli@wfp/cli@zaproxy/actions-common-scansaccept-to-ship-action@zephraph/servicescontribution-streak-maintainerantora-extensions-and-macroseslint-suggestion-actiongenaiscript
7.1.2

7 months ago

7.1.1

1 year ago

7.0.4

1 year ago

7.1.0

1 year ago

7.0.3

1 year ago

7.0.2

1 year ago

7.0.0

1 year ago

7.0.1

1 year ago

5.0.5

2 years ago

6.0.1

2 years ago

6.0.0

2 years ago

5.0.4

2 years ago

5.0.3

2 years ago

5.0.2

2 years ago

5.0.1

2 years ago

5.0.0

2 years ago

4.1.4

2 years ago

4.1.6

2 years ago

4.1.5

2 years ago

4.1.3

2 years ago

4.1.2

2 years ago

4.0.4

2 years ago

4.1.0

2 years ago

4.1.1

2 years ago

4.0.3

3 years ago

3.0.9

4 years ago

3.0.8

4 years ago

3.0.7

4 years ago

3.0.6

4 years ago

3.0.5

4 years ago

3.0.4

4 years ago

3.0.3

5 years ago

3.0.2

5 years ago

3.0.1

5 years ago

3.0.0

5 years ago

2.2.0

6 years ago

2.1.2

6 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.0

6 years ago

1.0.0

6 years ago