From afbebc977e4c40dece9ca5100cf6deedbf37d72a Mon Sep 17 00:00:00 2001 From: Jack Foltz Date: Wed, 25 Jul 2018 18:43:20 -0400 Subject: [PATCH] Add error handling middleware --- server.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/server.js b/server.js index 961ac21..3ec7266 100755 --- a/server.js +++ b/server.js @@ -55,6 +55,12 @@ app.use(express.static(__dirname + '/public')); require('./app/routes/routes.js')(app); require('./config/passport.js'); +// Error handler +app.use((err, req, res, next) => { + console.error(err.stack); + res.status(500).json({'message': 'Internal server error.'}); +}); + // Start app const port = process.env.PORT || 8080; const server = app.listen(port); @@ -63,7 +69,7 @@ console.log('Listening on port ' + port + '...\n'); // Handle sigint process.on('SIGINT', () => { console.log('Shutting down...'); - process.exitCode = 0; + process.exit(0); }); // Expose app