File tree Expand file tree Collapse file tree 1 file changed +14
-3
lines changed
Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Original file line number Diff line number Diff 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/**
You can’t perform that action at this time.
0 commit comments