-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy patherror-request.ts
More file actions
32 lines (28 loc) · 920 Bytes
/
error-request.ts
File metadata and controls
32 lines (28 loc) · 920 Bytes
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
// @ts-ignore
export async function errorRequest(state, octokit, error, options) {
if (!error.request || !error.request.request) {
// address https://github.com/octokit/plugin-retry.js/issues/8
throw error;
}
// retry all >= 400 && not doNotRetry
if (error.status >= 400 && !state.doNotRetry.includes(error.status)) {
const retries =
options.request.retries != null ? options.request.retries : state.retries;
const base = (options.request.retryCount || 0) + 1;
let retryAfter;
switch (state.strategy) {
case "exponential":
retryAfter = Math.pow(2, base);
break;
case "linear":
retryAfter = base;
break;
default: // "polynomial"
retryAfter = Math.pow(base, 2);
break;
}
throw octokit.retry.retryRequest(error, retries, retryAfter);
}
// Maybe eventually there will be more cases here
throw error;
}