Skip to content

Commit 9b44db3

Browse files
steam-games.js: Handle "no active giveaways" response
1 parent 34a6408 commit 9b44db3

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

steam-games.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,19 @@ async function fetchGamerPowerGiveaways() {
9797
throw new Error(`Failed to fetch GamerPower data: ${response.statusText}`);
9898
}
9999

100-
const items = await response.json();
101-
console.log(`Fetched ${items.length} giveaways from GamerPower`);
102-
return items;
100+
const data = await response.json();
101+
102+
// Handle "no active giveaways" response: {"status":0,"status_message":"No active giveaways available..."}
103+
if (!Array.isArray(data)) {
104+
if (data.status === 0 && data.status_message) {
105+
console.log(`GamerPower: ${data.status_message}`);
106+
return [];
107+
}
108+
throw new Error(`Unexpected GamerPower response: ${JSON.stringify(data)}`);
109+
}
110+
111+
console.log(`Fetched ${data.length} giveaways from GamerPower`);
112+
return data;
103113
}
104114

105115
function filterUnclaimedGiveaways(giveaways) {

0 commit comments

Comments
 (0)