Actually what you have done is somehow anti-pattern. I’ve experienced the pattern you mentioned and there are some subtle problems with.
Say we want to fetch some users and we have a GLOBAL error handler inside Express.js framework, consider code below:
app.get(‘/someRoute’, async (req, res, next)=>{
let foundUser = await USER.find().catch(error=>{
return next(handleError(error);
});
*res.send(‘we got the user’);
});
the point here is handleError, in my case I set up this global error handler with sending proper error message to the client. so headers are sent once, and after handling error we get to the scope * and response will be sent twice and you’ll encounter “headers cant be sent after they are sent” inside node.js
As a golden rule, it’s good to write no code after the catch block. since codes after the catch block will be executed always and this makes lots of confusion especially if you put this inside if-else blocks(my case);
So in my opinion try-catch is the winner.