web: make most client/network errors ignored by sentry

This commit is contained in:
Jens Langhammer 2020-12-12 23:32:55 +01:00
parent d2862ddc93
commit 434922f702
6 changed files with 31 additions and 5 deletions

View File

@ -2,6 +2,7 @@ import { DefaultClient } from "./client";
import * as Sentry from "@sentry/browser"; import * as Sentry from "@sentry/browser";
import { Integrations } from "@sentry/tracing"; import { Integrations } from "@sentry/tracing";
import { VERSION } from "../constants"; import { VERSION } from "../constants";
import { SentryIgnoredError } from "../common/errors";
export class Config { export class Config {
branding_logo: string; branding_logo: string;
@ -24,6 +25,12 @@ export class Config {
integrations: [new Integrations.BrowserTracing()], integrations: [new Integrations.BrowserTracing()],
tracesSampleRate: 1.0, tracesSampleRate: 1.0,
environment: config.error_reporting_environment, environment: config.error_reporting_environment,
beforeSend(event: Sentry.Event, hint: Sentry.EventHint) {
if (hint.originalException instanceof SentryIgnoredError) {
return null;
}
return event;
},
}); });
console.debug("authentik/config: Sentry enabled."); console.debug("authentik/config: Sentry enabled.");
} }

1
web/src/common/errors.ts Normal file
View File

@ -0,0 +1 @@
export class SentryIgnoredError extends Error {}

View File

@ -1,5 +1,6 @@
import { css, CSSResult, customElement, html, LitElement, property, TemplateResult } from "lit-element"; import { css, CSSResult, customElement, html, LitElement, property, TemplateResult } from "lit-element";
import Chart from "chart.js"; import Chart from "chart.js";
import { showMessage } from "./messages/MessageContainer";
interface TickValue { interface TickValue {
value: number; value: number;
@ -41,7 +42,13 @@ export class AdminLoginsChart extends LitElement {
firstUpdated(): void { firstUpdated(): void {
fetch(this.url) fetch(this.url)
.then((r) => r.json()) .then((r) => r.json())
.catch((e) => console.error(e)) .catch((e) => {
showMessage({
level_tag: "error",
message: "Unexpected error"
});
console.log(e);
})
.then((r) => { .then((r) => {
const canvas = <HTMLCanvasElement>this.shadowRoot?.querySelector("canvas"); const canvas = <HTMLCanvasElement>this.shadowRoot?.querySelector("canvas");
if (!canvas) { if (!canvas) {

View File

@ -13,6 +13,7 @@ import fa from "@fortawesome/fontawesome-free/css/solid.css";
import { convertToSlug } from "../../utils"; import { convertToSlug } from "../../utils";
import { SpinnerButton } from "./SpinnerButton"; import { SpinnerButton } from "./SpinnerButton";
import { PRIMARY_CLASS } from "../../constants"; import { PRIMARY_CLASS } from "../../constants";
import { showMessage } from "../messages/MessageContainer";
@customElement("ak-modal-button") @customElement("ak-modal-button")
export class ModalButton extends LitElement { export class ModalButton extends LitElement {
@ -110,7 +111,11 @@ export class ModalButton extends LitElement {
} }
}) })
.catch((e) => { .catch((e) => {
console.error(e); showMessage({
level_tag: "error",
message: "Unexpected error"
});
console.log(e);
}); });
}); });
}); });
@ -139,7 +144,11 @@ export class ModalButton extends LitElement {
}); });
}) })
.catch((e) => { .catch((e) => {
console.error(e); showMessage({
level_tag: "error",
message: "Unexpected error"
});
console.log(e);
}); });
} }
} }

View File

@ -1,4 +1,5 @@
import { LitElement, html, customElement, property, TemplateResult } from "lit-element"; import { LitElement, html, customElement, property, TemplateResult } from "lit-element";
import { SentryIgnoredError } from "../../common/errors";
enum ResponseType { enum ResponseType {
redirect = "redirect", redirect = "redirect",
@ -30,7 +31,7 @@ export class FlowShellCard extends LitElement {
// Fallback when the flow does not exist, just redirect to the root // Fallback when the flow does not exist, just redirect to the root
window.location.pathname = "/"; window.location.pathname = "/";
} else if (!r.ok) { } else if (!r.ok) {
throw Error(r.statusText); throw new SentryIgnoredError(r.statusText);
} }
return r; return r;
}) })

View File

@ -8,6 +8,7 @@ import BackdropStyle from "@patternfly/patternfly/components/Backdrop/backdrop.c
import { SpinnerSize } from "../../elements/Spinner"; import { SpinnerSize } from "../../elements/Spinner";
import { showMessage } from "../../elements/messages/MessageContainer"; import { showMessage } from "../../elements/messages/MessageContainer";
import { gettext } from "django"; import { gettext } from "django";
import { SentryIgnoredError } from "../../common/errors";
@customElement("ak-site-shell") @customElement("ak-site-shell")
export class SiteShell extends LitElement { export class SiteShell extends LitElement {
@ -70,7 +71,7 @@ export class SiteShell extends LitElement {
level_tag: "error", level_tag: "error",
message: gettext(`Request failed: ${r.statusText}`), message: gettext(`Request failed: ${r.statusText}`),
}); });
throw new Error("Request failed"); throw new SentryIgnoredError("Request failed");
}) })
.then((r) => r.text()) .then((r) => r.text())
.then((t) => { .then((t) => {