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 <jens@goauthentik.io>

* web: default to origin for API urls, this also makes urls in logs clickable

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

---------

Signed-off-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
Jens L 2023-08-26 17:26:28 +02:00 committed by GitHub
parent 599f7e7c88
commit 15e872762a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 3 deletions

View File

@ -63,7 +63,7 @@ export function getMetaContent(key: string): string {
} }
export const DEFAULT_CONFIG = new Configuration({ 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: { headers: {
"sentry-trace": getMetaContent("sentry-trace"), "sentry-trace": getMetaContent("sentry-trace"),
}, },

View File

@ -25,8 +25,13 @@ export class LoggingMiddleware implements Middleware {
post(context: ResponseContext): Promise<Response | void> { post(context: ResponseContext): Promise<Response | void> {
let msg = `authentik/api[${this.tenant.matchedDomain}]: `; let msg = `authentik/api[${this.tenant.matchedDomain}]: `;
msg += `${context.response.status} ${context.init.method} ${context.url}`; // https://developer.mozilla.org/en-US/docs/Web/API/console#styling_console_output
console.debug(msg); 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); return Promise.resolve(context.response);
} }
} }