Im trying to create an ObjectId with mongoose in my node.js app from the parameters in the route.
If I got this route:
/product/:id
and I try to create my ObjectId for quering the product collection I use this
var o_id = moongose.Types.ObjectId(req.params.id);
But if the :id part of the route is NOT an ObjectId string, just some random text I get an error:
"Argument passed in must be a single String of 12 bytes or a string of 24 hex characters"
How do I catch this error? I have tried to surround o_id = moongose.Types.ObjectId(req.params.id) with try{}catch(error) {} but I get nothing in the catch expression.