-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy patherror-request.ts
More file actions
48 lines (42 loc) · 1.25 KB
/
error-request.ts
File metadata and controls
48 lines (42 loc) · 1.25 KB
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
43
44
45
46
47
48
import {
type RequestOptionsWithRequest,
type RetryPlugin,
type RetryState,
} from "./types.js";
import { RequestError } from "@octokit/request-error";
export function isRequestError(error: any): error is RequestError {
return error.request !== undefined;
}
export function defaultShouldRetry(
state: RetryState,
error: RequestError | Error,
): boolean {
if (!isRequestError(error) || !error?.request.request) {
// address https://github.com/octokit/plugin-retry.js/issues/8
throw error;
}
return error.status >= 400 && !state.doNotRetry.includes(error.status);
}
export async function errorRequest(
state: RetryState,
octokit: RetryPlugin,
error: RequestError | Error,
options: RequestOptionsWithRequest,
): Promise<any> {
if (state.shouldRetry(state, error)) {
const retries: number =
options.request?.retries != null
? options.request.retries
: state.retries;
const retryAfter = Math.pow((options.request?.retryCount || 0) + 1, 2);
throw new RequestError(
error.message,
isRequestError(error) ? error.status : 500,
{
request: octokit.retry.retryRequest(options, retries, retryAfter),
},
);
}
// Maybe eventually there will be more cases here
throw error;
}