mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-11 10:43:20 +00:00
17 lines
397 B
TypeScript
17 lines
397 B
TypeScript
/**
|
|
* An equivalent to `fetch`, except will automatically retry.
|
|
*/
|
|
export const fetchRetry = (
|
|
url: string,
|
|
options?: RequestInit,
|
|
retryTimer: number = 1000
|
|
): Promise<Response> => {
|
|
return fetch(url, options).catch(() => {
|
|
return new Promise((resolve) => {
|
|
setTimeout(() => {
|
|
fetchRetry(url, options, retryTimer).then(resolve);
|
|
}, retryTimer);
|
|
});
|
|
});
|
|
};
|