Hi there
if anyone are facing the error that when the genre id is not correct and u wanna sho some response status and can’t send message of “Not found”
then replace this code:
router.get('/:id', async (req, res) => {
const genre = await Genre.findById(req.params.id);
if (!genre) return res.status(404).send('The genre with the given ID was not found.');
res.send(genre);
});
with this code :
router.get('/:id', async (req, res) => {
try {
const genre = await Genre.findById(req.params.id);
res.send(genre);
} catch (err) {
res.status(404).send("The genre with the given ID was not found.");
};
});