diff --git a/app/src/api/api.ts b/app/src/api/api.ts index 8b1a5f50..469e7e4c 100644 --- a/app/src/api/api.ts +++ b/app/src/api/api.ts @@ -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;