Here is my current code snippet for the /api/students/id route:
router.get('/:id',asyncHandler(async(req,res)=>{
const student = await Student.findById(req.params.id)
if(student){
res.json(student)
}
else{
res.status(404).json({message: 'Student not found'})
}
}))
export default router
Upon hitting the /api/students/{correct-Id}, I receive the correct student details. However, when I change the correct-Id to something different, an error occurs. Here's the link to the error message: https://i.sstatic.net/Yagyb.png
I am actually expecting the error message 'Student not found' in such cases. Any assistance would be greatly appreciated. Thank you.