Error handling middleware

pull/1/head
sundowndev 2018-11-14 18:16:33 +01:00
parent bd8d95a8b4
commit 0b1361263e
1 changed files with 4 additions and 0 deletions

View File

@ -9,6 +9,10 @@ const port = process.env.PORT || 8080; // set our port
app.use('/', routes);
app.use((err, req, res, next) => {
res.status(err.status || 400).json({ success: false, message: err.message || 'An error occured.', errors: err.error || [] });
});
app.use((req, res) => {
res.status(404).json({ message: 'Resource not found.' });
});