Skip to content

Commit

Permalink
serve pages for errors not in debug
Browse files Browse the repository at this point in the history
  • Loading branch information
edcohen08 committed Jul 25, 2023
1 parent 88c8d53 commit d6329d7
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ htmx.defineExtension("get-timezone", {
}
});

// This function will listen for HTMX errors and display the appropriate page
// as needed. Without debug mode enabled, HTMX will normally refuse to
// serve any HTML attached to an HTTP error code. This will allow us to present
// users with custom error pages.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
htmx.on("htmx:beforeOnLoad", (event:any) => {
const { xhr } = event.detail;
if (xhr.status === 500 || xhr.status === 404) {
event.stopPropagation();
document.children[0].innerHTML = xhr.response;
}
});

if (import.meta.hot) {
import.meta.hot.on("template-hmr", () => {
const dest = document.location.href;
Expand Down

0 comments on commit d6329d7

Please sign in to comment.