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 { 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,18 +208,26 @@ 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);
|
||||
|
||||
let ret = await executeRouteHandler(
|
||||
route_handler,
|
||||
window.location.pathname,
|
||||
args,
|
||||
);
|
||||
app.innerHTML = ret.html;
|
||||
if (ret.postInsert) {
|
||||
let r = ret.postInsert(app);
|
||||
if (r instanceof Promise) await r;
|
||||
try {
|
||||
let ret = await executeRouteHandler(
|
||||
route_handler,
|
||||
window.location.pathname,
|
||||
args,
|
||||
);
|
||||
app.innerHTML = ret.html;
|
||||
if (ret.postInsert) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue