The browser now keeps its half of the one event shape logs.py defines: lib/log.ts is a levelled, redacted, bounded (2000 events) in-memory ring with the server's level names and severity numbers. Nothing leaves the browser yet; sending is the consented diagnostics level (S5). - lib/http.ts `send` is the one fetch: every request carries an X-Request-Id and becomes one http.request event. The server echoes the matched route template in X-Route (only for a matched route, so a raw path with a value in it is never sent back); without one the client templates the path itself. req, beacon, the upload XHR, the public watch page and the legal pages all go through it. - Hooks: app start snapshot, uncaught errors and rejections, History push/replace/popstate (a scroll-only replace is not an event; parameter values only at DEBUG, typed search only at TRACE), notifications, the error dialog, the crash boundary, failed queries and mutations (key head only), and the messages socket (lifecycle, frame types at DEBUG). - Redaction is one contract: backend/tests/fixtures/log_redaction_cases.json runs against both redact() implementations. - Lint: fetch, XMLHttpRequest and WebSocket each belong to one logging module, console to none; a contract test proves the rules fire. Fixes a socket takeover: the close of a socket released by the last subscriber cleared the newer socket a quick re-subscribe had opened and scheduled a third, leaving two live sockets that delivered every message twice (measured in Chromium: 3 created / 2 live before, 2 / 1 after).
31 lines
1004 B
TypeScript
31 lines
1004 B
TypeScript
import i18n from "../i18n";
|
|
import { createStore } from "./store";
|
|
import { log } from "./log";
|
|
|
|
// A single, self-explanatory error dialog (modal) the user must acknowledge — used when the
|
|
// server can't carry out an action (a definitive 4xx/5xx response). Distinct from toasts
|
|
// (transient, e.g. connection blips) and from silent handling. Module-level so the non-React
|
|
// api layer can raise it; an <ErrorDialog> mounted at the app root renders the current one.
|
|
interface AppError {
|
|
title: string;
|
|
message: string;
|
|
}
|
|
|
|
const store = createStore<AppError | null>(null);
|
|
|
|
export function reportError(message?: string, title?: string): void {
|
|
const shown = {
|
|
title: title || i18n.t("errors.title"),
|
|
message: message || i18n.t("errors.generic"),
|
|
};
|
|
log.error("ui.error_dialog", shown.message, { title: shown.title });
|
|
store.set(shown);
|
|
}
|
|
|
|
export function dismissError(): void {
|
|
store.set(null);
|
|
}
|
|
|
|
export const subscribeError = store.subscribe;
|
|
export const getError = store.get;
|