Refactor for better API

This commit is contained in:
Andras Schmelczer 2025-01-02 20:56:35 +00:00
commit c3781a432e
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C

View file

@ -1,4 +1,5 @@
import * as fetchRetryFactory from "fetch-retry"; import * as fetchRetryFactory from "fetch-retry";
import { RequestInitRetryParams } from "fetch-retry";
import { Logger } from "src/tracing/logger"; import { Logger } from "src/tracing/logger";
const fetchWithRetry = fetchRetryFactory.default(fetch); const fetchWithRetry = fetchRetryFactory.default(fetch);
@ -15,10 +16,9 @@ function getUrlFromInput(input: RequestInfo | URL): string {
export async function retriedFetch( export async function retriedFetch(
input: RequestInfo | URL, input: RequestInfo | URL,
init: RequestInit = {} init: RequestInitRetryParams<typeof fetch> = {}
): Promise<Response> { ): Promise<Response> {
return fetchWithRetry(input, { return fetchWithRetry(input, {
...init,
retryOn: function (attempt, error, response) { retryOn: function (attempt, error, response) {
if (error !== null || !response || response.status >= 500) { if (error !== null || !response || response.status >= 500) {
Logger.getInstance().warn( Logger.getInstance().warn(
@ -33,5 +33,6 @@ export async function retriedFetch(
}, },
retries: 6, retries: 6,
retryDelay: (attempt) => Math.pow(1.5, attempt) * 500, retryDelay: (attempt) => Math.pow(1.5, attempt) * 500,
...init,
}); });
} }