Skip to content

Commit 5be07e4

Browse files
committed
fix: added buttons to 404 and 500 pages, ensure that page rendered not just for 500
1 parent 9b49b01 commit 5be07e4

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

404.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
<body>
5656
<h1>Page Not Found</h1>
5757
<p>Sorry, but the page you were trying to view does not exist.</p>
58+
<button onclick="javascript:window.location = '/';">Go to homepage</button>
5859
</body>
5960
</html>
6061
<!-- IE needs 512+ bytes: https://docs.microsoft.com/en-us/archive/blogs/ieinternals/friendly-http-error-pages -->

500.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
<body>
5656
<h1>Internal Server Error</h1>
5757
<p>An internal server error occurred.</p>
58+
<button onclick="javascript:document.location.reload(true);">Try again</button>
5859
</body>
5960
</html>
6061
<!-- IE needs 512+ bytes: https://docs.microsoft.com/en-us/archive/blogs/ieinternals/friendly-http-error-pages -->

index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ const opts = {
5353
encoding: 'utf8'
5454
};
5555

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

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

203-
// render the 500 page
206+
// render the 5xx page
204207
if (hasRender) {
205208
try {
206209
await this.render('500');

0 commit comments

Comments
 (0)