Skip to content
This repository has been archived by the owner on Oct 14, 2022. It is now read-only.

Commit

Permalink
Add html error pages
Browse files Browse the repository at this point in the history
  • Loading branch information
pfrazee committed Jun 28, 2017
1 parent 2ee2dbe commit e25c70f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
5 changes: 5 additions & 0 deletions assets/css/pages/error.less
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
main.error {
text-align: center;

.alert {
margin: 1rem auto;
}

a {
&:extend(.link);
Expand Down
2 changes: 1 addition & 1 deletion assets/html/error.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<main class="error">
<div class="container">
<h1><%= error.status || 500 %> - Error</h1>
<p><%= error.message || error.body.message %></p>
<p class="alert warning" role="alert"><%= error.message || error.body.message %></p>
<p>Lost? <a href="/support">Contact Support</a></p>
</div>
</main>
Expand Down
14 changes: 11 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ module.exports = function (config) {
// =

app.use((err, req, res, next) => {
var contentType = req.accepts('json')
var contentType = req.accepts(['json', 'html'])
if (!contentType) {
return next()
}
Expand All @@ -204,7 +204,11 @@ module.exports = function (config) {
// common errors
if ('status' in err) {
res.status(err.status)
res.json(err.body)
if (contentType === 'json') {
res.json(err.body)
} else {
res.render('error', { error: err })
}
return
}

Expand All @@ -215,7 +219,11 @@ module.exports = function (config) {
message: 'Internal server error',
internalError: true
}
res.json(error)
if (contentType === 'json') {
res.json(error)
} else {
res.render('error', { error })
}
})

// error handling
Expand Down

0 comments on commit e25c70f

Please sign in to comment.