Home > Mobile >  Axios PUT request failed with 500 code Cast to ObjectId failed for value
Axios PUT request failed with 500 code Cast to ObjectId failed for value

Time:06-15

I'm new to MERN stack and I'm trying to make a put request with axios to change the user profile information but I'm getting the following error as a response : {"message":"Cast to ObjectId failed for value "profile" (type string) at path "_id" for model "User""} Here is the entire project : https://github.com/burNN11/new-project

CodePudding user response:

So you have the following in the router:

  • router.put('/:id')
  • router.put('/profile')

When you make a PUT request to /profile, express will invoke the first route (/:id), and treats profile as an id.

Solution: change your route name to PUT /profile/:id

  • Related