diff --git a/plugins/auth-oauth2/src/getAccessToken.ts b/plugins/auth-oauth2/src/getAccessToken.ts index 0304916f..1129508a 100644 --- a/plugins/auth-oauth2/src/getAccessToken.ts +++ b/plugins/auth-oauth2/src/getAccessToken.ts @@ -53,11 +53,11 @@ export async function getAccessToken( const resp = await ctx.httpRequest.send({ httpRequest }); - if (resp.status < 200 || resp.status >= 300) { - throw new Error('Failed to fetch access token with status=' + resp.status); - } + const body = resp.bodyPath ? readFileSync(resp.bodyPath, 'utf8') : ''; - const body = readFileSync(resp.bodyPath ?? '', 'utf8'); + if (resp.status < 200 || resp.status >= 300) { + throw new Error('Failed to fetch access token with status=' + resp.status + ' and body=' + body); + } let response; try { diff --git a/plugins/auth-oauth2/src/getOrRefreshAccessToken.ts b/plugins/auth-oauth2/src/getOrRefreshAccessToken.ts index 02ff377f..43df1402 100644 --- a/plugins/auth-oauth2/src/getOrRefreshAccessToken.ts +++ b/plugins/auth-oauth2/src/getOrRefreshAccessToken.ts @@ -73,11 +73,11 @@ export async function getOrRefreshAccessToken(ctx: Context, contextId: string, { return null; } - if (resp.status < 200 || resp.status >= 300) { - throw new Error('Failed to fetch access token with status=' + resp.status); - } + const body = resp.bodyPath ? readFileSync(resp.bodyPath, 'utf8') : ''; - const body = readFileSync(resp.bodyPath ?? '', 'utf8'); + if (resp.status < 200 || resp.status >= 300) { + throw new Error('Failed to refresh access token with status=' + resp.status + ' and body=' + body); + } let response; try {