Skip to content

Commit

Permalink
fix: added buttons to 404 and 500 pages, ensure that page rendered no…
Browse files Browse the repository at this point in the history
…t just for 500
  • Loading branch information
titanism committed Jun 3, 2022
1 parent 9b49b01 commit 5be07e4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions 404.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<body>
<h1>Page Not Found</h1>
<p>Sorry, but the page you were trying to view does not exist.</p>
<button onclick="javascript:window.location = '/';">Go to homepage</button>
</body>
</html>
<!-- IE needs 512+ bytes: https://docs.microsoft.com/en-us/archive/blogs/ieinternals/friendly-http-error-pages -->
1 change: 1 addition & 0 deletions 500.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<body>
<h1>Internal Server Error</h1>
<p>An internal server error occurred.</p>
<button onclick="javascript:document.location.reload(true);">Try again</button>
</body>
</html>
<!-- IE needs 512+ bytes: https://docs.microsoft.com/en-us/archive/blogs/ieinternals/friendly-http-error-pages -->
7 changes: 5 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ const opts = {
encoding: 'utf8'
};

//
// TODO: we could eventually use this https://github.com/alexphelps/server-error-pages/
//
// error pages were inspired by HTML5 Boilerplate's default 404.html page
// https://github.com/h5bp/html5-boilerplate/blob/master/src/404.html
const _404 = fs.readFileSync(path.join(__dirname, '404.html'), opts);
Expand Down Expand Up @@ -192,15 +195,15 @@ function errorHandler(
} else {
this.body = _404;
}
} else if (noReferrer || this.status === 500) {
} else if (noReferrer) {
// this prevents a redirect loop by detecting an empty Referrer
// ...otherwise it would reach the next conditional block which
// would endlessly rediret the user with `this.redirect('back')`

// flash an error message
if (hasFlash) this.flash('error', err.message);

// render the 500 page
// render the 5xx page
if (hasRender) {
try {
await this.render('500');
Expand Down

0 comments on commit 5be07e4

Please sign in to comment.