Skip to content

Commit 0d601d5

Browse files
authored
fix: prevent process.exit(1) on single user API failure (#61) (#128)
1 parent 0a53e10 commit 0d601d5

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

scripts/sync-leaderboard.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ const path = require("path");
66

77
async function fetchData(url) {
88
try {
9-
const res = await axios.get(url);
9+
const res = await axios.get(url, { timeout: 15000 });
1010
return {
1111
easySolved: res.data.easySolved || 0,
1212
mediumSolved: res.data.mediumSolved || 0,
1313
hardSolved: res.data.hardSolved || 0,
1414
};
1515
} catch (err) {
16-
console.error("API failed to respond: ", err.message);
17-
process.exit(1);
16+
console.error(`API failed for ${url}: ${err.message}`);
17+
return null;
1818
}
1919
}
2020

@@ -121,6 +121,10 @@ async function computeRankChanges(currentSorted, filename) {
121121
console.log("Starting daily fetch...");
122122
for (const user of users) {
123123
const data = await fetchData(baseUrl + user.id);
124+
if (!data) {
125+
console.log(`${user.name}: skipped (API error)`);
126+
continue;
127+
}
124128
const score = data.easySolved + data.mediumSolved * 3 + data.hardSolved * 5;
125129
console.log(`${user.name}:`, data);
126130
overallData.push({

0 commit comments

Comments
 (0)