Skip to content

Commit

Permalink
🔨 make it possible to specify fetch options for fetchWithRetry
Browse files Browse the repository at this point in the history
  • Loading branch information
danyx23 committed Nov 28, 2024
1 parent 1d3baad commit a570ac6
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/@ourworldindata/utils/src/Util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -784,14 +784,18 @@ interface RetryOptions {

export async function fetchWithRetry(
url: string,
options?: RetryOptions
fetchOptions?: RequestInit,
retryOptions?: RetryOptions
): Promise<Response> {
const defaultRetryOptions: RetryOptions = {
maxRetries: 5,
exponentialBackoff: true,
initialDelay: 250,
}
return retryPromise(() => fetch(url), options ?? defaultRetryOptions)
return retryPromise(
() => fetch(url, fetchOptions),
retryOptions ?? defaultRetryOptions
)
}
export async function retryPromise<T>(
promiseGetter: () => Promise<T>,
Expand Down

0 comments on commit a570ac6

Please sign in to comment.