1 | import { errorRequest } from "./error-request";
|
2 | import { wrapRequest } from "./wrap-request";
|
3 | export const VERSION = "0.0.0-development";
|
4 | export function retry(octokit, octokitOptions = {}) {
|
5 | const state = Object.assign({
|
6 | enabled: true,
|
7 | retryAfterBaseValue: 1000,
|
8 | doNotRetry: [400, 401, 403, 404, 422],
|
9 | retries: 3,
|
10 | }, octokitOptions.retry);
|
11 | octokit.retry = {
|
12 | retryRequest: (error, retries, retryAfter) => {
|
13 | error.request.request = Object.assign({}, error.request.request, {
|
14 | retries: retries,
|
15 | retryAfter: retryAfter,
|
16 | });
|
17 | return error;
|
18 | },
|
19 | };
|
20 | if (!state.enabled) {
|
21 | return;
|
22 | }
|
23 | octokit.hook.error("request", errorRequest.bind(null, octokit, state));
|
24 | octokit.hook.wrap("request", wrapRequest.bind(null, state));
|
25 | }
|
26 | retry.VERSION = VERSION;
|