Fix empty subscriptions page crash
Fix issue where when Twitch returns an empty page of subscribers, the app crashes due to trying to get response.data[0].user_id where response.data[0] is undefined Also adds some debug loggingmaster
parent
ac953b0bb5
commit
dd423bdb34
|
@ -35,9 +35,9 @@ export async function processSubscriptions(streamer: twitch.StreamerUserIdTokenP
|
|||
var oldFirstUserid = response.data[0].user_id;
|
||||
response = await twitch.streamerApiRequest(streamer,
|
||||
`/subscriptions?broadcaster_id=${streamer.userid}&after=${response.pagination.cursor}&first=100`);
|
||||
if (oldFirstUserid == response.data[0].user_id) break;
|
||||
log(LogLevel.DEBUG,"Subscription API response:");
|
||||
log(LogLevel.DEBUG,JSON.stringify(response,null,2));
|
||||
if (response.data.length === 0 || oldFirstUserid === response.data[0].user_id) break;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
@ -45,6 +45,7 @@ export async function processSubscriptions(streamer: twitch.StreamerUserIdTokenP
|
|||
await dbconn.query("CALL update_scores()");
|
||||
await dbconn.query('COMMIT');
|
||||
} catch (e) {
|
||||
log(LogLevel.ERROR,"cronjobs.processSubscriptions: Exception: " + e);
|
||||
log(LogLevel.ERROR,"cronjobs.processSubscriptions: Exception thrown; rolling back");
|
||||
await dbconn.query('ROLLBACK');
|
||||
throw(e);
|
||||
|
|
|
@ -53,6 +53,7 @@ export async function apiRequest(tokens: TokenPair, endpoint: string): Promise <
|
|||
return fetch("https://api.twitch.tv/helix" + endpoint, { headers: headers })
|
||||
.then(async (res: FetchResponse) => {
|
||||
if (res.status == 200) {
|
||||
log(LogLevel.DEBUG,"twitch.apiRequest: Request returned 200 for " + endpoint);
|
||||
return res.json();
|
||||
} else {
|
||||
log(LogLevel.WARNING,"twitch.apiRequest: Failed API request (pre-refresh):");
|
||||
|
|
Loading…
Reference in New Issue