mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 18:57:03 +02:00
22 lines
491 B
TypeScript
22 lines
491 B
TypeScript
export async function patientFetch(
|
|
url: string,
|
|
timeout = 1000,
|
|
options?: Partial<{ cache: 'no-store' }>,
|
|
) {
|
|
let patientResponse: Response;
|
|
|
|
while (patientResponse! === undefined) {
|
|
try {
|
|
patientResponse = await fetch(url, options);
|
|
} catch (error) {
|
|
console.warn(
|
|
`Failed to fetch ${url}; retrying in ${timeout}ms...`,
|
|
error,
|
|
);
|
|
await new Promise((resolve) => setTimeout(resolve, timeout));
|
|
}
|
|
}
|
|
|
|
return patientResponse;
|
|
}
|