Add logging on failed API requests

master
Dessa Simpson 2020-09-14 22:34:17 -07:00
parent b1d44d3af3
commit 85b48f90f4
1 changed files with 7 additions and 2 deletions

View File

@ -19,7 +19,6 @@ async function refreshApiToken(tokens: TokenPair): Promise<boolean> {
}).then(async (res: FetchResponse) => {
if (res.status == 200) {
var data = await (res.json() as Promise<TokenPair>);
console.log(data)
tokens.access_token = data.access_token;
tokens.refresh_token = data.refresh_token;
return true;
@ -43,10 +42,16 @@ export async function apiRequest(tokens: TokenPair, endpoint: string): Promise <
} else {
if (refreshApiToken(tokens)) {
return fetch("https://api.twitch.tv/helix" + endpoint, { headers: headers })
.then((res: FetchResponse) => {
.then(async (res: FetchResponse) => {
if (res.status == 200) {
return res.json();
} else {
console.log("Failed API request:");
console.log("Request URL: https://api.twitch.tv/helix" + endpoint);
console.log("Headers: ");
console.log(headers);
console.log("Response: ");
console.log(await res.json());
return false;
}
})