-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should ref.get()
throw a 404 error when requesting a missing document?
#36
Comments
Issue-Label Bot is automatically applying the label Links: app homepage, dashboard and code for this bot. |
I'm lazy and would prefer B. It would probably be nice to have an option (strict mode or something) that will then turn on Option A |
@dflorey Thanks for sharing your opinion. As for now, it seems like that would be the direction we will take. |
In my opinion, the client library should not have opinions on how a server responds to the request. It is good to document unexpected behavior (code errors and messages) and encourage the library users to take errors responsibly. Just my 2 cents |
As I see it, returning Just to complete the discussion, I'll add that Firebase SDK handles it this way:
This two-step process is redundant in my mind, though we can see that the developers migrating from Firebase SDK might expects this behavior. Meaning -
Thanks for the discussion, stay safe. |
Yes, the official API gives you an object |
@sesam to be honest I don't like much the official API, and I think it can be improved, so regarding your question about deferring the parsing of the data, I don't think its a good API design. |
Hi everyone.
Since this question doesn't really have a correct answer I wanted to ask you guys, the community what do to.
Right now, when making a request for a document that doesn't exist by using the
reference.get()
method, the method will throw a 404 error.I was asked by a member of the community to re-evaluate if this should be the case, and I think he has a point.
Option A:
Returning a 404 error forces you to use try/catch clauses and provide some logic to when the document doesn't exist, and in the end of the day, it "forces" the developer to write better code.
Option B:
The alternative is to return
null
orundefined
, and that way even if the document doesn't exist, it is up to the developer to decide whether to handle that or not.Other methods:
When calling
update
orset
on a non-existing document the default behavior is:set
if the document doesn't exist the one with the same id will be created, and the data will be set as requested.update
an error will be thrown in order to avoid creating a partial document, however, this can be overwritten.Please let me know what is your opinion on the matter.
The text was updated successfully, but these errors were encountered: