Error handling middleware
parent
bd8d95a8b4
commit
0b1361263e
4
index.js
4
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.' });
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue