From 7ddb4590301eb5590898f004456fce36ceba055d Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Fri, 9 Jul 2021 19:06:30 +0200 Subject: [PATCH] web: fix error when showing error message of request Signed-off-by: Jens Langhammer --- web/package.json | 2 +- web/src/api/Config.ts | 3 ++- web/src/api/Sentry.ts | 4 +++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/web/package.json b/web/package.json index 0c607dafe..2f620834f 100644 --- a/web/package.json +++ b/web/package.json @@ -7,7 +7,7 @@ "extract": "lingui extract", "build": "lingui compile && rollup -c ./rollup.config.js", "watch": "lingui compile && rollup -c -w", - "lint": "eslint . --max-warnings 0", + "lint": "eslint . --max-warnings 0 --fix", "lit-analyse": "lit-analyzer src" }, "lingui": { diff --git a/web/src/api/Config.ts b/web/src/api/Config.ts index 530d0f5fd..6d4d9c6a4 100644 --- a/web/src/api/Config.ts +++ b/web/src/api/Config.ts @@ -10,7 +10,8 @@ export class LoggingMiddleware implements Middleware { let msg = `authentik/api[${tenant.matchedDomain}]: `; msg += `${context.response.status} ${context.init.method} ${context.url}`; if (context.response.status >= 400) { - context.response.text().then(t => { + const resClone = context.response.clone(); + resClone.text().then(t => { msg += ` => ${t}`; console.debug(msg); }); diff --git a/web/src/api/Sentry.ts b/web/src/api/Sentry.ts index 008069359..6e939f79f 100644 --- a/web/src/api/Sentry.ts +++ b/web/src/api/Sentry.ts @@ -37,7 +37,9 @@ export function configureSentry(canDoPpi: boolean = false): Promise { if (response.status < 500) { return null; } - const body = await response.json(); + // Need to clone the response, otherwise the .text() and .json() can't be re-used + const resCopy = response.clone(); + const body = await resCopy.json(); event.message = `${response.status} ${response.url}: ${JSON.stringify(body)}` } if (event.exception) {