mirror of
https://github.com/hanzoai/sentinel.git
synced 2026-09-29 22:34:33 +00:00
24 lines
468 B
TypeScript
24 lines
468 B
TypeScript
import {isWebpackChunkLoadingError} from 'sentry/utils';
|
|
|
|
const MAX_RETRIES = 2;
|
|
|
|
export default function retryableImport<T>(
|
|
fn: () => Promise<{default: T}>
|
|
): Promise<{default: T}> {
|
|
let retries = 0;
|
|
const tryLoad = async () => {
|
|
try {
|
|
return await fn();
|
|
} catch (err) {
|
|
if (isWebpackChunkLoadingError(err) && retries < MAX_RETRIES) {
|
|
retries++;
|
|
return tryLoad();
|
|
}
|
|
|
|
throw err;
|
|
}
|
|
};
|
|
|
|
return tryLoad();
|
|
}
|