Skip to content

Commit

Permalink
Merge pull request #30 from octotravel/feat/shoud-force-retry-async
Browse files Browse the repository at this point in the history
shouldForceRetry is async
  • Loading branch information
Faboslav authored Sep 2, 2024
2 parents 843a641 + 48816d7 commit a77ac14
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@octocloud/core",
"version": "1.0.59",
"version": "1.0.60",
"license": "ISC",
"author": "",
"exports": {
Expand Down
8 changes: 4 additions & 4 deletions src/util/fetchRetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ const FETCH_RETRY_DEFAULT_OPTIONS = {
currentRetryAttempt: 0,
maxRetryAttempts: DEFAULT_MAX_RETRY_ATTEMPTS,
retryDelayMultiplierInMs: DEFAULT_RETRY_DELAY_MULTIPLIER_IN_MS,
shouldForceRetry: (status: number, response: Response) => false,
shouldForceRetry: async (status: number, response: Response) => false,
};

export interface FetchRetryOptions {
subRequestContext?: SubRequestContext | null;
currentRetryAttempt?: number;
maxRetryAttempts?: number;
retryDelayMultiplierInMs?: number;
shouldForceRetry?: (status: number, response: Response) => boolean;
shouldForceRetry?: (status: number, response: Response) => Promise<boolean>;
}

export async function fetchRetry(
Expand All @@ -29,7 +29,7 @@ export async function fetchRetry(
currentRetryAttempt = 0,
maxRetryAttempts = DEFAULT_MAX_RETRY_ATTEMPTS,
retryDelayMultiplierInMs = DEFAULT_RETRY_DELAY_MULTIPLIER_IN_MS,
shouldForceRetry = (status: number, response: Response) => false,
shouldForceRetry = async (status: number, response: Response) => false,
} = options;
let subRequestRetryContext: SubRequestRetryContext | null = null;
let request: Request;
Expand Down Expand Up @@ -84,7 +84,7 @@ export async function fetchRetry(
const status = res.status;

if (
((status >= 500 && status < 599) || status === 429 || shouldForceRetry(status, res.clone())) &&
((status >= 500 && status < 599) || status === 429 || (await shouldForceRetry(status, res.clone()))) &&
currentRetryAttempt < maxRetryAttempts
) {
return await fetchRetry(request, undefined, {
Expand Down

0 comments on commit a77ac14

Please sign in to comment.