mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-09-27 10:53:50 +02:00
Add fetchFn to UrlSourceOptions, allow Request as UrlSource input, pass error message to getRetryDelay, add fallback for Blob.stream()
This commit is contained in:
+5
-4
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user