UNPKG

2.44 kBMarkdownView Raw
1# plugin-retry.js
2
3> Retries requests for server 4xx/5xx responses except `400`, `401`, `403` and `404`.
4
5[![@latest](https://img.shields.io/npm/v/@octokit/plugin-retry.svg)](https://www.npmjs.com/package/@octokit/plugin-retry)
6[![Build Status](https://github.com/octokit/plugin-retry.js/workflows/Test/badge.svg)](https://github.com/octokit/plugin-retry.js/actions?workflow=Test)
7[![Greenkeeper](https://badges.greenkeeper.io/octokit/plugin-retry.js.svg)](https://greenkeeper.io/)
8
9## Usage
10
11<table>
12<tbody valign=top align=left>
13<tr><th>
14Browsers
15</th><td width=100%>
16
17Load `@octokit/plugin-retry` and [`@octokit/core`](https://github.com/octokit/core.js) (or core-compatible module) directly from [cdn.pika.dev](https://cdn.pika.dev)
18
19```html
20<script type="module">
21 import { Octokit } from "https://cdn.pika.dev/@octokit/core";
22 import { retry } from "https://cdn.pika.dev/@octokit/plugin-retry";
23</script>
24```
25
26</td></tr>
27<tr><th>
28Node
29</th><td>
30
31Install with `npm install @octokit/core @octokit/plugin-retry`. Optionally replace `@octokit/core` with a core-compatible module
32
33```js
34const { Octokit } = require("@octokit/core");
35const { retry } = require("@octokit/plugin-retry");
36```
37
38</td></tr>
39</tbody>
40</table>
41
42```js
43const MyOctokit = Octokit.plugin(retry);
44const octokit = new MyOctokit({ auth: "secret123" });
45
46// retries request up to 3 times in case of a 500 response
47octokit.request("/").catch(error => {
48 if (error.request.request.retryCount) {
49 console.log(
50 `request failed after ${error.request.request.retryCount} retries`
51 );
52 }
53
54 console.error(error);
55});
56```
57
58To override the default `doNotRetry` list:
59
60```js
61const octokit = new MyOctokit({
62 retry: {
63 doNotRetry: [
64 /* List of HTTP 4xx/5xx status codes */
65 ]
66 }
67});
68```
69
70To override the number of retries:
71
72```js
73const octokit = new MyOctokit({
74 request: { retries: 1 }
75});
76```
77
78You can manually ask for retries for any request by passing `{ request: { retries: numRetries, retryAfter: delayInSeconds }}`
79
80```js
81octokit
82 .request("/", { request: { retries: 1, retryAfter: 1 } })
83 .catch(error => {
84 if (error.request.request.retryCount) {
85 console.log(
86 `request failed after ${error.request.request.retryCount} retries`
87 );
88 }
89
90 console.error(error);
91 });
92```
93
94Pass `{ retry: { enabled: false } }` to disable this plugin.
95
96## Contributing
97
98See [CONTRIBUTING.md](CONTRIBUTING.md)
99
100## License
101
102[MIT](LICENSE)