Add global error handler

This commit is contained in:
Maciej Ziarkowski 2019-08-21 14:47:44 +01:00
parent 4d27c3b889
commit 2622269f77

View File

@ -90,8 +90,20 @@ server.get('/search', function (req, res) {
}); });
}) })
server.use((err, req, res, next) => {
if (res.headersSent) {
return next(err);
}
if (err != undefined) {
console.log('Global error handler: ', err);
res.status(500).send({ error: 'Server error' });
}
});
server.use((req, res) => { server.use((req, res) => {
res.status(404).json({ error: 'Resource not found'}); res.status(404).json({ error: 'Resource not found'});
}) })
export default server; export default server;