From b25c933ea5820298ceb110ed510034307227bd3b 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 85707b645c..3bbc7b76e4 100644 --- a/server.js +++ b/server.js @@ -322,6 +322,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.')