From e15b9e24982bfd7e09536b55f4043af4fb4464c2 Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Thu, 2 Jan 2025 20:44:04 +0000 Subject: [PATCH] Lint retried fetch --- plugin/src/utils/retried-fetch.ts | 50 ++++++++++++++----------------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/plugin/src/utils/retried-fetch.ts b/plugin/src/utils/retried-fetch.ts index de40d3d4..474ead36 100644 --- a/plugin/src/utils/retried-fetch.ts +++ b/plugin/src/utils/retried-fetch.ts @@ -3,33 +3,6 @@ import { Logger } from "src/tracing/logger"; const fetchWithRetry = fetchRetryFactory.default(fetch); -export async function retriedFetch( - input: RequestInfo | URL, - init: RequestInit = {} -): Promise { - return fetchWithRetry(input, { - ...init, - retryOn: function (attempt, error, response) { - // retry on any network error, or 4xx or 5xx status codes - if (error !== null || !response || response.status >= 500) { - Logger.getInstance().warn( - `Retrying fetch attempt ${attempt} for ${getUrlFromInput( - input - )}` - ); - - return true; - } - return false; - }, - retries: 6, - retryDelay: function (attempt) { - Logger; - return Math.pow(1.5, attempt) * 500; - }, - }); -} - function getUrlFromInput(input: RequestInfo | URL): string { if (input instanceof URL) { return input.href; @@ -39,3 +12,26 @@ function getUrlFromInput(input: RequestInfo | URL): string { } return input.url; } + +export async function retriedFetch( + input: RequestInfo | URL, + init: RequestInit = {} +): Promise { + return fetchWithRetry(input, { + ...init, + retryOn: function (attempt, error, response) { + if (error !== null || !response || response.status >= 500) { + Logger.getInstance().warn( + `Retrying fetch for ${getUrlFromInput( + input + )}, attempt ${attempt}` + ); + + return true; + } + return false; + }, + retries: 6, + retryDelay: (attempt) => Math.pow(1.5, attempt) * 500, + }); +}