Skip to content

Commit

Permalink
fix: improve to getWorldInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
ultraviolet-jordan committed Feb 4, 2024
1 parent 3ad3fad commit 8156faf
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/js/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10555,11 +10555,16 @@ async function getWorldInfo(secured: boolean, id: number, retries: number = 0):
}
// github host is secured for example.
const url: string = secured ? 'https://2004scape.org/api/v1/worldlist' : 'http://2004scape.org/api/v1/worldlist';
const worldlist: WorldList[] = JSON.parse(await downloadText(url));
const world: WorldList | undefined = worldlist.find((x): boolean => x.id === id);
if (!world) {
let worldlist: WorldList[];
try {
worldlist = JSON.parse(await downloadText(url));
} catch (e) {
await sleep(1000);
return getWorldInfo(secured, id, ++retries);
}
const world: WorldList | undefined = worldlist.find((x): boolean => x.id === id);
if (!world) {
return getWorldInfo(secured, id, 10);
}
return world;
}

0 comments on commit 8156faf

Please sign in to comment.