mirror of
https://github.com/VOREStation/VOREStation.git
synced 2026-07-20 19:44:46 +01:00
retry refmap (#19007)
This commit is contained in:
@@ -12,10 +12,7 @@ export function handleLoadAssets(payload: Record<string, string>): void {
|
||||
Byond.iconRefMap &&
|
||||
Object.keys(Byond.iconRefMap).length === 0
|
||||
) {
|
||||
fetchRetry(payload['icon_ref_map.json'])
|
||||
.then((res) => res.json())
|
||||
.then(setIconRefMap)
|
||||
.catch(console.error);
|
||||
fetchIconRefMapWithRetry(payload['icon_ref_map.json']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,3 +26,26 @@ export function getIconFromRefMap(icon: string): string | undefined {
|
||||
function setIconRefMap(map: Record<string, string>): void {
|
||||
Byond.iconRefMap = map;
|
||||
}
|
||||
|
||||
function fetchIconRefMapWithRetry(url: string, retries = 5, delay = 2500) {
|
||||
const attempt = () => {
|
||||
fetchRetry(url)
|
||||
.then((res) => res.json())
|
||||
.then((json) => {
|
||||
setIconRefMap(json);
|
||||
console.log('Icon ref map loaded successfully.');
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(`Failed to load icon_ref_map.json:`, err);
|
||||
if (retries > 0) {
|
||||
console.log(`Retrying in ${delay / 1000}s...`);
|
||||
setTimeout(
|
||||
() => fetchIconRefMapWithRetry(url, retries - 1, delay),
|
||||
delay,
|
||||
);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
attempt();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user