Add fetchFn to UrlSourceOptions, allow Request as UrlSource input, pass error message to getRetryDelay, add fallback for Blob.stream()

This commit is contained in:
Vanilagy
2025-09-22 11:10:39 +02:00
parent 63145c9ced
commit 15db099caf
3 changed files with 91 additions and 32 deletions
+5 -4
View File
@@ -575,18 +575,19 @@ const normalizeHeaders = (headers: HeadersInit): Record<string, string> => {
};
export const retriedFetch = async (
url: string | URL,
fetchFn: typeof fetch,
url: string | URL | Request,
requestInit: RequestInit,
getRetryDelay: (previousAttempts: number) => number | null,
getRetryDelay: (previousAttempts: number, error: unknown) => number | null,
) => {
let attempts = 0;
while (true) {
try {
return await fetch(url, requestInit);
return await fetchFn(url, requestInit);
} catch (error) {
attempts++;
const retryDelayInSeconds = getRetryDelay(attempts);
const retryDelayInSeconds = getRetryDelay(attempts, error);
if (retryDelayInSeconds === null) {
throw error;