Skip to content

ConvertNulltoNotFoundError when calling DataAccessObject.findOne via rest#135

Merged
raymondfeng merged 1 commit intoloopbackio:masterfrom
albertoleal:ConvertNullToNotFoundError
Jun 19, 2014
Merged

ConvertNulltoNotFoundError when calling DataAccessObject.findOne via rest#135
raymondfeng merged 1 commit intoloopbackio:masterfrom
albertoleal:ConvertNullToNotFoundError

Conversation

@albertoleal
Copy link
Copy Markdown
Contributor

When we call the url http://localhost:3000/api/cars/1 with an invalid id we get a 404 error:

{
error: {
name: "Error",
status: 404,
message: "Unknown "cars" id "1".",
statusCode: 404,
stack: "Error: Unknown "cars" id 1". at Function...
} 
} 

But, when we try to use filters, such as http://localhost:3000/api/cars/findOne?filter%5Bwhere%5D%5Bid%5D=1, we have another behavior:

null

This PR follows the same approach found in: https://github.com/strongloop/loopback-datasource-juggler/blob/master/lib/dao.js#L364-L371

@slnode
Copy link
Copy Markdown

slnode commented Jun 11, 2014

Can one of the admins verify this patch? To accept patch and trigger a build add comment ".ok\W+to\W+test."

@albertoleal
Copy link
Copy Markdown
Contributor Author

Hi, do you any feedback about this pr?

@raymondfeng
Copy link
Copy Markdown
Contributor

Thanks for the patch.

I'm not fully convinced whether reporting 404 is a good idea for findOne when no records are found. Maybe we should have a discussion on the group.

@albertoleal
Copy link
Copy Markdown
Contributor Author

I understand that we should discuss about it on the group, but that's the same behavior we have for findById.

@ricobl
Copy link
Copy Markdown

ricobl commented Jun 14, 2014

I agree with @albertoleal, the message we're passing when we return a success response in this case is that the object exists and it is null.

A client should be able to consume both a findById URL and a findOne URL seamlessly with the same implementation.

Right now it has to deal with a success, a null success and errors.

raymondfeng added a commit that referenced this pull request Jun 19, 2014
ConvertNulltoNotFoundError when calling DataAccessObject.findOne via rest
@raymondfeng raymondfeng merged commit 26501ea into loopbackio:master Jun 19, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants