catching global exceptions

This commit is contained in:
Maieul BOYER 2026-01-13 17:05:53 +01:00 committed by Nigel
parent 30540bfe92
commit 6fa846f1e2
2 changed files with 31 additions and 11 deletions

View file

@ -0,0 +1,10 @@
<div class="base-box displaybox">
<div id="mainbox" class="pong-mainboxDisplay rounded-elem">
<div class="text-7xl text-red-800 font-bold mt-4 mb-2">An Error Has Occured</div>
<span class="text-base text-red-700 font-semibold mb-4" id="error-msg"></span>
<button class="w-full bg-amber-600 text-white font-medium py-2 rounded-xl hover:bg-amber-700 transition mt-4" onclick="navigateTo('/')">
Return To Home Page
</button>
</div>
</div>

View file

@ -1,5 +1,6 @@
import { updateUser } from "@app/auth";
import { ensureWindowState, escapeHTML } from "@app/utils";
import errorPage from "./errorPage.html?raw";
ensureWindowState();
@ -14,7 +15,8 @@ declare module "ft_state" {
window.__state.routes ??= new Map();
window.__state.title ??= "";
window.__state.titleElem ??= document.querySelector<HTMLDivElement>("#header-title")!;
window.__state.titleElem ??=
document.querySelector<HTMLDivElement>("#header-title")!;
window.__state._routingHandler ??= false;
// ---- Router logic ----
@ -206,9 +208,12 @@ export async function handleRoute() {
);
const app = document.getElementById("app")!;
const event = new CustomEvent("ft:pageChange", { detail: window.location.pathname });
const event = new CustomEvent("ft:pageChange", {
detail: window.location.pathname,
});
document.dispatchEvent(event);
try {
let ret = await executeRouteHandler(
route_handler,
window.location.pathname,
@ -219,6 +224,11 @@ export async function handleRoute() {
let r = ret.postInsert(app);
if (r instanceof Promise) await r;
}
} catch (e: any) {
app.innerHTML = errorPage;
let err = app.querySelector("#error-msg");
if (err) err.innerHTML = e.toString();
}
}
if (!window.__state._routingHandler) {