Skip to content

Commit 97547bb

Browse files
fetchGamerPowerGiveaways: handle status_message
1 parent 2608f74 commit 97547bb

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/gp.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,20 @@ async function fetchGamerPowerGiveaways(apiUrl) {
2121
throw new Error(`Failed to fetch GamerPower data: ${response.statusText}`);
2222
}
2323

24-
const items = await response.json();
25-
console.log(`[GamerPower] Fetched ${items.length} giveaways`);
26-
return items;
24+
const data = await response.json();
25+
26+
// API returns {status: 0, status_message: "..."} when no giveaways available
27+
if (!Array.isArray(data)) {
28+
const NO_GIVEAWAYS_MSG = 'No active giveaways available at the moment, please try again later.';
29+
if (data.status_message === NO_GIVEAWAYS_MSG) {
30+
console.log('[GamerPower] No active giveaways available');
31+
return [];
32+
}
33+
throw new Error(`GamerPower API error: ${data.status_message || JSON.stringify(data)}`);
34+
}
35+
36+
console.log(`[GamerPower] Fetched ${data.length} giveaways`);
37+
return data;
2738
}
2839

2940
/**

0 commit comments

Comments
 (0)