diff --git a/index.js b/index.js index ff252bf..559c3ab 100644 --- a/index.js +++ b/index.js @@ -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.' }); });