2023-11-14 13:42:15 -06:00
|
|
|
export async function patientFetch(
|
|
|
|
|
url: string,
|
|
|
|
|
timeout = 1000,
|
|
|
|
|
options?: Partial<{ cache: 'no-store' }>,
|
|
|
|
|
) {
|
2023-11-07 18:58:19 -06:00
|
|
|
let patientResponse: Response;
|
|
|
|
|
|
|
|
|
|
while (patientResponse! === undefined) {
|
|
|
|
|
try {
|
2023-11-14 13:42:15 -06:00
|
|
|
patientResponse = await fetch(url, options);
|
2023-11-07 18:58:19 -06:00
|
|
|
} catch (error) {
|
2023-11-14 13:42:15 -06:00
|
|
|
console.warn(
|
|
|
|
|
`Failed to fetch ${url}; retrying in ${timeout}ms...`,
|
|
|
|
|
error,
|
|
|
|
|
);
|
2023-11-07 18:58:19 -06:00
|
|
|
await new Promise((resolve) => setTimeout(resolve, timeout));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return patientResponse;
|
|
|
|
|
}
|