From c73f0b02bd1fd9dae2aed2db965cf4c608953281 Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Fri, 16 May 2025 08:16:18 -0700 Subject: [PATCH] print body in OAuth 2 http errors --- plugins/auth-oauth2/src/getAccessToken.ts | 8 ++++---- plugins/auth-oauth2/src/getOrRefreshAccessToken.ts | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) 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 {