From c3da12f703b1197e96c522fdbc88c6edae06def2 Mon Sep 17 00:00:00 2001 From: Joe Lanman Date: Wed, 18 Jul 2018 11:54:20 +0100 Subject: [PATCH] Add error handling --- server.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/server.js b/server.js index 5f4018f4c1..7de71d6381 100644 --- a/server.js +++ b/server.js @@ -317,6 +317,19 @@ app.post(/^\/([^.]+)$/, function (req, res) { res.redirect('/' + req.params[0]) }) +// catch 404 and forward to error handler +app.use(function (req, res, next) { + var err = new Error('Page not found') + err.status = 404 + next(err) +}) + +// display error +app.use(function (err, req, res, next) { + res.status(err.status || 500) + res.send(err.message) +}) + console.log('\nGOV.UK Prototype Kit v' + releaseVersion) console.log('\nNOTICE: the kit is for building prototypes, do not use it for production services.')