1
0
mirror of https://github.com/Foltik/Shimapan synced 2024-11-10 15:48:27 -05:00

Add error handling middleware

This commit is contained in:
Jack Foltz 2018-07-25 18:43:20 -04:00
parent a00a3efbf6
commit afbebc977e
Signed by: foltik
GPG Key ID: 303F88F996E95541

View File

@ -55,6 +55,12 @@ app.use(express.static(__dirname + '/public'));
require('./app/routes/routes.js')(app); require('./app/routes/routes.js')(app);
require('./config/passport.js'); 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 // Start app
const port = process.env.PORT || 8080; const port = process.env.PORT || 8080;
const server = app.listen(port); const server = app.listen(port);
@ -63,7 +69,7 @@ console.log('Listening on port ' + port + '...\n');
// Handle sigint // Handle sigint
process.on('SIGINT', () => { process.on('SIGINT', () => {
console.log('Shutting down...'); console.log('Shutting down...');
process.exitCode = 0; process.exit(0);
}); });
// Expose app // Expose app