Skip to content

Commit

Permalink
when fetching mod data retry 2 times on failure
Browse files Browse the repository at this point in the history
  • Loading branch information
Shazbot committed Jul 12, 2023
1 parent 604c3c3 commit 5941754
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/modFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ import * as nodePath from "path";
import * as fsExtra from "fs-extra";
import * as os from "os";

export function fetchModData(ids: string[], cb: (modData: ModData) => void, log: (msg: string) => void) {
export function fetchModData(
ids: string[],
cb: (modData: ModData) => void,
log: (msg: string) => void,
retryIndex = 0
) {
ids.forEach(async (workshopId) => {
fetch(`https://steamcommunity.com/sharedfiles/filedetails/?id=${workshopId}`)
.then((res) => res.text())
Expand Down Expand Up @@ -137,7 +142,13 @@ export function fetchModData(ids: string[], cb: (modData: ModData) => void, log:
cb(modData);
}
})
.catch();
.catch(async () => {
if (retryIndex < 3) {
log(`Retrying fetching mod data for mod with id ${workshopId}, retry number ${retryIndex}`);
await new Promise((resolve) => setTimeout(resolve, 1000));
fetchModData([workshopId], cb, log, retryIndex + 1);
}
});
});
}

Expand Down

0 comments on commit 5941754

Please sign in to comment.