diff --git a/web/src/api/Client.ts b/web/src/api/Client.ts index 55c593759..6f6359d69 100644 --- a/web/src/api/Client.ts +++ b/web/src/api/Client.ts @@ -1,3 +1,5 @@ +import { gettext } from "django"; +import { showMessage } from "../elements/messages/MessageContainer"; import { getCookie } from "../utils"; import { NotFoundError, RequestError } from "./Error"; @@ -47,6 +49,13 @@ export class Client { } return r; }) + .catch((e) => { + showMessage({ + level_tag: "error", + message: gettext(`Unexpected error while fetching: ${e.toString()}`), + }); + return e; + }) .then((r) => r.json()) .then((r) => r); } diff --git a/web/src/elements/AdminLoginsChart.ts b/web/src/elements/AdminLoginsChart.ts index 63d1b3c35..3d154fa54 100644 --- a/web/src/elements/AdminLoginsChart.ts +++ b/web/src/elements/AdminLoginsChart.ts @@ -1,16 +1,21 @@ import { css, CSSResult, customElement, html, LitElement, property, TemplateResult } from "lit-element"; import Chart from "chart.js"; -import { showMessage } from "./messages/MessageContainer"; +import { DefaultClient } from "../api/Client"; interface TickValue { value: number; major: boolean; } +export interface LoginMetrics { + logins_failed_per_1h: { x: number, y: number }[]; + logins_per_1h: { x: number, y: number }[]; +} + @customElement("ak-admin-logins-chart") export class AdminLoginsChart extends LitElement { @property() - url = ""; + url: string[] = []; chart?: Chart; @@ -40,15 +45,7 @@ export class AdminLoginsChart extends LitElement { } firstUpdated(): void { - fetch(this.url) - .then((r) => r.json()) - .catch((e) => { - showMessage({ - level_tag: "error", - message: "Unexpected error" - }); - console.error(e); - }) + DefaultClient.fetch(this.url) .then((r) => { const canvas = this.shadowRoot?.querySelector("canvas"); if (!canvas) { diff --git a/web/src/pages/admin-overview/AdminOverviewPage.ts b/web/src/pages/admin-overview/AdminOverviewPage.ts index 49df2ab09..7ccab4064 100644 --- a/web/src/pages/admin-overview/AdminOverviewPage.ts +++ b/web/src/pages/admin-overview/AdminOverviewPage.ts @@ -1,6 +1,5 @@ import { gettext } from "django"; import { CSSResult, customElement, html, LitElement, TemplateResult } from "lit-element"; -import { DefaultClient } from "../../api/Client"; import { COMMON_STYLES } from "../../common/styles"; import "../../elements/AdminLoginsChart"; @@ -31,7 +30,7 @@ export class AdminOverviewPage extends LitElement {