fix: patient JSON parsing

This commit is contained in:
TrèsAbhi committed 2023-11-16 11:41:52 -06:00
1 parent ee6d2e7d82
commit e0a719ee93
3 files changed
+32 -13

No files matched your search

+23
View File
@@ -0,0 +1,23 @@
export async function patientFetchJSON<Type extends object>(
url: string,
timeout = 1000,
options?: Partial<{ cache: 'no-store' }>,
) {
let patientJSON: Type;
while (patientJSON! === undefined) {
try {
patientJSON = (await fetch(url, options).then(({ json }) =>
json(),
)) as Type;
} catch (error) {
console.warn(
`Failed to fetch ${url} as JSON; retrying in ${timeout}ms...`,
error,
);
await new Promise((resolve) => setTimeout(resolve, timeout));
}
}
return patientJSON;
}