baugarten/node-restful

Cast to ObjectId failed for value XXX at path "_id"

brunobraga opened this issue · 1 comments

From the version/example to date, sending a request with an invalid numeric ID cases the response to be returned status_code 500 with the output:

GET /note/1 500 53.133 ms - 131
{
message: "Cast to ObjectId failed for value "1" at path "_id"",
name: "CastError",
kind: "ObjectId",
value: "1",
path: "_id"
}

This happens in case the mongoose schema was designed using default ID values (assumes it as ObjectID instead), causes it to return error 500, which should be 404 (even if you don't check the DB).

More info on this:
http://stackoverflow.com/questions/14940660/whats-mongoose-error-cast-to-objectid-failed-for-value-xxx-at-path-id
http://stackoverflow.com/questions/14940660/whats-mongoose-error-cast-to-objectid-failed-for-value-xxx-at-path-id

the version/example to date, sending a request with an invalid numeric ID cases the response to be returned status_code 500 with the output:

GET /note/1 500 53.133 ms - 131
{
message: "Cast to ObjectId failed for value "1" at path "_id"",
name: "CastError",
kind: "ObjectId",
value: "1",
path: "_id"
}
This happens in case the mongoose schema was designed using default ID values (assumes it as ObjectID instead), causes it to return error 500, which should be 404 (even if you don't check the DB).

More info on this:
http://stackoverflow.com/questions/14940660/whats-mongoose-error-cast-to-objectid-failed-for-value-xxx-at-path-id
http://stackoverflow.com/questions/14940660/whats-mongoose-error-cast-to-objectid-failed-for-value-xxx-at-path-id