Skip to content

Sending PUT /todos/201 on a created todo with id 201 returns 500 #98

@tommywalkie

Description

@tommywalkie

Hi,
When I edit a todo resource and send a PUT /todos/200 request, it works and returns the updated fake JSON data.

{
  "id": 200,
  "title": "edited title",
  "userId": 10,
  "completed": true
}

When I create a todo resource with POST /todos, it worked and I could get a todo with id 201.

{
  "title": "test",
  "userId": 1,
  "completed": false,
  "id": 201
}

But I try to edit the todo resource and send a PUT /todos/201 request with these body :

{
  "title": "edited test todo title",
  "userId": 1,
  "completed": false,
  "id": 201
}

... It returns an 500 Internal Server Error.

TypeError: Cannot read property 'id' of undefined
    at update (/app/node_modules/json-server/lib/server/router/plural.js:258:24)
    at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
    at next (/app/node_modules/express/lib/router/route.js:137:13)
    at next (/app/node_modules/express/lib/router/route.js:131:14)
    at Route.dispatch (/app/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
    at /app/node_modules/express/lib/router/index.js:281:22
    at param (/app/node_modules/express/lib/router/index.js:354:14)
    at param (/app/node_modules/express/lib/router/index.js:365:14)
    at Function.process_params (/app/node_modules/express/lib/router/index.js:410:3)

Note : This error doesn't occur when I delete this todo resource with DELETE /todos/201
Looks like a json-server specific problem, but just to be sure, am I doing something wrong ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions