From c3079a198d9bd7fb748750ff4fec2171107a3dbb Mon Sep 17 00:00:00 2001 From: Dessa Simpson Date: Mon, 9 Nov 2020 16:24:34 -0700 Subject: [PATCH] Specify source of log messages in twitch.ts --- src/twitch.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/twitch.ts b/src/twitch.ts index 24e6322..e44b303 100644 --- a/src/twitch.ts +++ b/src/twitch.ts @@ -12,7 +12,7 @@ export interface TokenPair { // Refresh the API token. Returns true on success and false on failure. async function refreshApiToken(tokens: TokenPair): Promise { - log(LogLevel.DEBUG,`Call: refreshApiToken(${JSON.stringify(tokens,null,2)})`); + log(LogLevel.DEBUG,`Call: twitch.refreshApiToken(${JSON.stringify(tokens,null,2)})`); return fetch("https://id.twitch.tv/oauth2/token", { method: 'POST', body: new URLSearchParams({ @@ -23,7 +23,7 @@ async function refreshApiToken(tokens: TokenPair): Promise { }) }).then(async (res: FetchResponse) => { if (res.status == 200) { - log(LogLevel.INFO,"Refresh returned success."); + log(LogLevel.INFO,"twitch.refreshApiToken: Refresh returned success."); var data = await (res.json() as Promise); log(LogLevel.DEBUG, "Returned data:") log(LogLevel.DEBUG, data) @@ -31,7 +31,7 @@ async function refreshApiToken(tokens: TokenPair): Promise { tokens.refresh_token = data.refresh_token; return true; } else { - log(LogLevel.ERROR,"Refresh returned failure. Response object:"); + log(LogLevel.ERROR,"twitch.refreshApiToken: Refresh returned failure. Response object:"); log(LogLevel.ERROR,JSON.stringify(await res.json(),null,2)); return false; } @@ -41,7 +41,7 @@ async function refreshApiToken(tokens: TokenPair): Promise { // Send an API request. On success, return the specified data. On failure, // attempt to refresh the API token and retry export async function apiRequest(tokens: TokenPair, endpoint: string): Promise { - log(LogLevel.DEBUG,`Call: apiRequest(${JSON.stringify(tokens,null,2)},${endpoint})`); + log(LogLevel.DEBUG,`Call: twitch.apiRequest(${JSON.stringify(tokens,null,2)},${endpoint})`); var headers = { "Authorization": "Bearer " + tokens.access_token, "Client-ID": config.twitchClientId @@ -51,7 +51,7 @@ export async function apiRequest(tokens: TokenPair, endpoint: string): Promise < if (res.status == 200) { return res.json(); } else { - log(LogLevel.WARNING,"Failed API request (pre-refresh):"); + log(LogLevel.WARNING,"twitch.apiRequest: Failed API request (pre-refresh):"); log(LogLevel.WARNING,"Request URL: https://api.twitch.tv/helix" + endpoint); log(LogLevel.WARNING,"Headers:"); log(LogLevel.WARNING,JSON.stringify(headers,null,2)); @@ -66,7 +66,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.WARNING,"API call succeeded after token refresh.") + log(LogLevel.WARNING,"twitch.apiRequest: API call succeeded after token refresh.") return res.json(); } else { log(LogLevel.ERROR,"Failed API request:"); @@ -86,7 +86,7 @@ export async function apiRequest(tokens: TokenPair, endpoint: string): Promise < } export async function streamerApiRequest(endpoint: string) { - log(LogLevel.DEBUG,`Call: streamerApiRequest(${endpoint})`); + log(LogLevel.DEBUG,`Call: twitch.streamerApiRequest(${endpoint})`); var streamer = await db.query(queries.getStreamerIdToken).then((result: pg.QueryResult) => result.rows[0]); var tokenpair = streamer.tokenpair; var originaltoken = tokenpair.access_token; @@ -101,7 +101,7 @@ export async function streamerApiRequest(endpoint: string) { // success, return true. If failure, return the result of attempting to refresh // the API token. export async function isApiTokenValid(tokens: TokenPair) { - log(LogLevel.DEBUG,`Call: isApiTokenValid(${JSON.stringify(tokens,null,2)})`); + log(LogLevel.DEBUG,`Call: twitch.isApiTokenValid(${JSON.stringify(tokens,null,2)})`); return fetch("https://id.twitch.tv/oauth2/validate", { headers: {'Authorization': `OAuth ${tokens.access_token}`} }).then((res: FetchResponse) => {