When the document with the given id is not found, the catch block gets executed. But when document is not found, then findById returns null and so it should send 404 and not 500 status code.
app.get('/users/:id', (req, res) => {
const _id = req.params.id;
User.findById(_id).then((user) => {
if (!user) {
return res.status(404).send()
}
res.send(user)
}).catch((error) => {
res.status(500).send()
})
})