Sunday 24 May 2020

Getting error based on where I place my route

HiI'm getting a weird error with one of my routes on my express app. I have a list routesrouter.get('/property', catchErrors(propertyController.getAllProperty)); router.get('/property/:id', catchErrors(propertyController.getProperty)); router.get('/property/add/', propertyController.addProperty); router.post('/property', catchErrors(propertyController.createProperty)); router.get('/property/edit', propertyController.editProperty); router.put('/property/:id', catchErrors(propertyController.updateProperty)); router.delete('/property/:id', catchErrors(propertyController.deleteProperty));When I hit the following route `/property/add/`, I get the following error `Cast to ObjectId failed for value "add" at path "_id" for model "Property"`.All I'm trying to do is render out a simple json placeholder like thisexports.addProperty = (req, res) => {res.json('Form for adding new property');};However if I move the route above the rest, it works as expected. Any ideas?

Submitted May 24, 2020 at 07:33PM by Deviso

No comments:

Post a Comment