-
Notifications
You must be signed in to change notification settings - Fork 18
/
index.ts
42 lines (36 loc) · 1021 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { Octokit } from "@octokit/core";
import { RequestError } from "@octokit/request-error";
import { errorRequest } from "./error-request";
import { wrapRequest } from "./wrap-request";
export const VERSION = "0.0.0-development";
export function retry(octokit: Octokit, octokitOptions: any) {
const state = Object.assign(
{
enabled: true,
retryAfterBaseValue: 1000,
doNotRetry: [400, 401, 403, 404, 422],
retries: 3,
},
octokitOptions.retry
);
if (state.enabled) {
octokit.hook.error("request", errorRequest.bind(null, octokit, state));
octokit.hook.wrap("request", wrapRequest.bind(null, state));
}
return {
retry: {
retryRequest: (
error: RequestError,
retries: number,
retryAfter: number
) => {
error.request.request = Object.assign({}, error.request.request, {
retries: retries,
retryAfter: retryAfter,
});
return error;
},
},
};
}
retry.VERSION = VERSION;