catching global exceptions
This commit is contained in:
parent
30540bfe92
commit
6fa846f1e2
2 changed files with 31 additions and 11 deletions
10
frontend/src/errorPage.html
Normal file
10
frontend/src/errorPage.html
Normal 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>
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import { updateUser } from "@app/auth";
|
import { updateUser } from "@app/auth";
|
||||||
import { ensureWindowState, escapeHTML } from "@app/utils";
|
import { ensureWindowState, escapeHTML } from "@app/utils";
|
||||||
|
import errorPage from "./errorPage.html?raw";
|
||||||
|
|
||||||
ensureWindowState();
|
ensureWindowState();
|
||||||
|
|
||||||
|
|
@ -14,7 +15,8 @@ declare module "ft_state" {
|
||||||
|
|
||||||
window.__state.routes ??= new Map();
|
window.__state.routes ??= new Map();
|
||||||
window.__state.title ??= "";
|
window.__state.title ??= "";
|
||||||
window.__state.titleElem ??= document.querySelector<HTMLDivElement>("#header-title")!;
|
window.__state.titleElem ??=
|
||||||
|
document.querySelector<HTMLDivElement>("#header-title")!;
|
||||||
window.__state._routingHandler ??= false;
|
window.__state._routingHandler ??= false;
|
||||||
|
|
||||||
// ---- Router logic ----
|
// ---- Router logic ----
|
||||||
|
|
@ -206,9 +208,12 @@ export async function handleRoute() {
|
||||||
);
|
);
|
||||||
const app = document.getElementById("app")!;
|
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);
|
document.dispatchEvent(event);
|
||||||
|
|
||||||
|
try {
|
||||||
let ret = await executeRouteHandler(
|
let ret = await executeRouteHandler(
|
||||||
route_handler,
|
route_handler,
|
||||||
window.location.pathname,
|
window.location.pathname,
|
||||||
|
|
@ -219,6 +224,11 @@ export async function handleRoute() {
|
||||||
let r = ret.postInsert(app);
|
let r = ret.postInsert(app);
|
||||||
if (r instanceof Promise) await r;
|
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) {
|
if (!window.__state._routingHandler) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue