Add global error handler
This commit is contained in:
parent
4d27c3b889
commit
2622269f77
@ -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) => {
|
||||
res.status(404).json({ error: 'Resource not found'});
|
||||
})
|
||||
|
||||
|
||||
export default server;
|
||||
|
Loading…
Reference in New Issue
Block a user