Keep failures connected to the request
app.get('/notes/:id', async (req, res, next) => {
try {
const note = await notes.findById(req.params.id);
res.json(note);
} catch (error) {
next(error);
}
});Awaiting the repository call lets the handler pass rejection to Express error middleware. Nest later performs this translation through its request pipeline and exception filters.