From 434922f70234fd653619dc45a413df703dd59120 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sat, 12 Dec 2020 23:32:55 +0100 Subject: [PATCH] web: make most client/network errors ignored by sentry --- web/src/api/config.ts | 7 +++++++ web/src/common/errors.ts | 1 + web/src/elements/AdminLoginsChart.ts | 9 ++++++++- web/src/elements/buttons/ModalButton.ts | 13 +++++++++++-- web/src/pages/generic/FlowShellCard.ts | 3 ++- web/src/pages/generic/SiteShell.ts | 3 ++- 6 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 web/src/common/errors.ts diff --git a/web/src/api/config.ts b/web/src/api/config.ts index 529fd2cd1..fa55b11d7 100644 --- a/web/src/api/config.ts +++ b/web/src/api/config.ts @@ -2,6 +2,7 @@ import { DefaultClient } from "./client"; import * as Sentry from "@sentry/browser"; import { Integrations } from "@sentry/tracing"; import { VERSION } from "../constants"; +import { SentryIgnoredError } from "../common/errors"; export class Config { branding_logo: string; @@ -24,6 +25,12 @@ export class Config { integrations: [new Integrations.BrowserTracing()], tracesSampleRate: 1.0, 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."); } diff --git a/web/src/common/errors.ts b/web/src/common/errors.ts new file mode 100644 index 000000000..652c5a315 --- /dev/null +++ b/web/src/common/errors.ts @@ -0,0 +1 @@ +export class SentryIgnoredError extends Error {} diff --git a/web/src/elements/AdminLoginsChart.ts b/web/src/elements/AdminLoginsChart.ts index 4142a2177..898d59d0a 100644 --- a/web/src/elements/AdminLoginsChart.ts +++ b/web/src/elements/AdminLoginsChart.ts @@ -1,5 +1,6 @@ import { css, CSSResult, customElement, html, LitElement, property, TemplateResult } from "lit-element"; import Chart from "chart.js"; +import { showMessage } from "./messages/MessageContainer"; interface TickValue { value: number; @@ -41,7 +42,13 @@ export class AdminLoginsChart extends LitElement { firstUpdated(): void { fetch(this.url) .then((r) => r.json()) - .catch((e) => console.error(e)) + .catch((e) => { + showMessage({ + level_tag: "error", + message: "Unexpected error" + }); + console.log(e); + }) .then((r) => { const canvas = this.shadowRoot?.querySelector("canvas"); if (!canvas) { diff --git a/web/src/elements/buttons/ModalButton.ts b/web/src/elements/buttons/ModalButton.ts index 2e7f2cf59..ba27fbd4f 100644 --- a/web/src/elements/buttons/ModalButton.ts +++ b/web/src/elements/buttons/ModalButton.ts @@ -13,6 +13,7 @@ import fa from "@fortawesome/fontawesome-free/css/solid.css"; import { convertToSlug } from "../../utils"; import { SpinnerButton } from "./SpinnerButton"; import { PRIMARY_CLASS } from "../../constants"; +import { showMessage } from "../messages/MessageContainer"; @customElement("ak-modal-button") export class ModalButton extends LitElement { @@ -110,7 +111,11 @@ export class ModalButton extends LitElement { } }) .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) => { - console.error(e); + showMessage({ + level_tag: "error", + message: "Unexpected error" + }); + console.log(e); }); } } diff --git a/web/src/pages/generic/FlowShellCard.ts b/web/src/pages/generic/FlowShellCard.ts index 79e789fba..b0df8bfd4 100644 --- a/web/src/pages/generic/FlowShellCard.ts +++ b/web/src/pages/generic/FlowShellCard.ts @@ -1,4 +1,5 @@ import { LitElement, html, customElement, property, TemplateResult } from "lit-element"; +import { SentryIgnoredError } from "../../common/errors"; enum ResponseType { redirect = "redirect", @@ -30,7 +31,7 @@ export class FlowShellCard extends LitElement { // Fallback when the flow does not exist, just redirect to the root window.location.pathname = "/"; } else if (!r.ok) { - throw Error(r.statusText); + throw new SentryIgnoredError(r.statusText); } return r; }) diff --git a/web/src/pages/generic/SiteShell.ts b/web/src/pages/generic/SiteShell.ts index d0c3f0f80..373669e3e 100644 --- a/web/src/pages/generic/SiteShell.ts +++ b/web/src/pages/generic/SiteShell.ts @@ -8,6 +8,7 @@ import BackdropStyle from "@patternfly/patternfly/components/Backdrop/backdrop.c import { SpinnerSize } from "../../elements/Spinner"; import { showMessage } from "../../elements/messages/MessageContainer"; import { gettext } from "django"; +import { SentryIgnoredError } from "../../common/errors"; @customElement("ak-site-shell") export class SiteShell extends LitElement { @@ -70,7 +71,7 @@ export class SiteShell extends LitElement { level_tag: "error", message: gettext(`Request failed: ${r.statusText}`), }); - throw new Error("Request failed"); + throw new SentryIgnoredError("Request failed"); }) .then((r) => r.text()) .then((t) => {