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 mounted at the app root renders the current one. interface AppError { title: string; message: string; } const store = createStore(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;