-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy patherror-request.ts
More file actions
31 lines (26 loc) · 1.03 KB
/
error-request.ts
File metadata and controls
31 lines (26 loc) · 1.03 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
import { type RetryPlugin, type RetryState } from "./types.js";
import type { RequestRequestOptions } from "@octokit/types";
import type { RequestError } from "@octokit/request-error";
export function isRequestError(error: any): error is RequestError {
return error.request !== undefined;
}
export async function errorRequest(
state: RetryState,
octokit: RetryPlugin,
error: RequestError | Error,
options: { request: RequestRequestOptions },
): Promise<any> {
if (!isRequestError(error) || !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 retryAfter = Math.pow((options.request.retryCount || 0) + 1, 2);
throw octokit.retry.retryRequest(error, retries, retryAfter);
}
// Maybe eventually there will be more cases here
throw error;
}