https://github.com/octokit/plugin-retry.js
Octokit plugin for GitHub’s recommended request retries
https://github.com/octokit/plugin-retry.js
hacktoberfest octokit-js plugin
Last synced: 7 months ago
JSON representation
Octokit plugin for GitHub’s recommended request retries
- Host: GitHub
- URL: https://github.com/octokit/plugin-retry.js
- Owner: octokit
- License: mit
- Created: 2018-12-27T16:56:58.000Z (about 7 years ago)
- Default Branch: main
- Last Pushed: 2025-05-12T22:11:27.000Z (8 months ago)
- Last Synced: 2025-05-14T11:51:48.568Z (8 months ago)
- Topics: hacktoberfest, octokit-js, plugin
- Language: TypeScript
- Homepage:
- Size: 2.96 MB
- Stars: 44
- Watchers: 11
- Forks: 22
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
# plugin-retry.js
> Retries requests for server 4xx/5xx responses except `400`, `401`, `403`, `404`, `410`, `422`, and `451`.
[](https://www.npmjs.com/package/@octokit/plugin-retry)
[](https://github.com/octokit/plugin-retry.js/actions?workflow=Test)
## Usage
Browsers
Load `@octokit/plugin-retry` and [`@octokit/core`](https://github.com/octokit/core.js) (or core-compatible module) directly from [esm.sh](https://esm.sh)
```html
import { Octokit } from "https://esm.sh/@octokit/core";
import { retry } from "https://esm.sh/@octokit/plugin-retry";
```
Node
Install with `npm install @octokit/core @octokit/plugin-retry`. Optionally replace `@octokit/core` with a core-compatible module
```js
import { Octokit } from "@octokit/core";
import { retry } from "@octokit/plugin-retry";
```
> [!IMPORTANT]
> As we use [conditional exports](https://nodejs.org/api/packages.html#conditional-exports), you will need to adapt your `tsconfig.json` by setting `"moduleResolution": "node16", "module": "node16"`.
>
> See the TypeScript docs on [package.json "exports"](https://www.typescriptlang.org/docs/handbook/modules/reference.html#packagejson-exports).
> See this [helpful guide on transitioning to ESM](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c) from [@sindresorhus](https://github.com/sindresorhus)
```js
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:
```js
const octokit = new MyOctokit({
auth: "secret123",
retry: {
doNotRetry: [
/* List of HTTP 4xx/5xx status codes */
],
},
});
```
To override the number of retries:
```js
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.
```js
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](CONTRIBUTING.md)
## License
[MIT](LICENSE)