From 15e872762a5598728ca8fa23690c28889fb47abf Mon Sep 17 00:00:00 2001 From: Jens L Date: Sat, 26 Aug 2023 17:26:28 +0200 Subject: [PATCH] web/common: make API errors more prominent in developer tools (#6637) * web/common: make API errors more common in developer tools Signed-off-by: Jens Langhammer * web: default to origin for API urls, this also makes urls in logs clickable Signed-off-by: Jens Langhammer --------- Signed-off-by: Jens Langhammer --- web/src/common/api/config.ts | 2 +- web/src/common/api/middleware.ts | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/web/src/common/api/config.ts b/web/src/common/api/config.ts index 4e120a38e..6276ec8a5 100644 --- a/web/src/common/api/config.ts +++ b/web/src/common/api/config.ts @@ -63,7 +63,7 @@ export function getMetaContent(key: string): string { } export const DEFAULT_CONFIG = new Configuration({ - basePath: process.env.AK_API_BASE_PATH + "/api/v3", + basePath: (process.env.AK_API_BASE_PATH || window.location.origin) + "/api/v3", headers: { "sentry-trace": getMetaContent("sentry-trace"), }, diff --git a/web/src/common/api/middleware.ts b/web/src/common/api/middleware.ts index b6f77ec47..745a5d1c9 100644 --- a/web/src/common/api/middleware.ts +++ b/web/src/common/api/middleware.ts @@ -25,8 +25,13 @@ export class LoggingMiddleware implements Middleware { post(context: ResponseContext): Promise { let msg = `authentik/api[${this.tenant.matchedDomain}]: `; - msg += `${context.response.status} ${context.init.method} ${context.url}`; - console.debug(msg); + // https://developer.mozilla.org/en-US/docs/Web/API/console#styling_console_output + msg += `%c${context.response.status}%c ${context.init.method} ${context.url}`; + let style = ""; + if (context.response.status >= 400) { + style = "color: red; font-weight: bold;"; + } + console.debug(msg, style, ""); return Promise.resolve(context.response); } }