Skip to content
This repository has been archived by the owner on Apr 11, 2023. It is now read-only.

error callback should be called if online fetch fails and no local cache is available #91

Closed
davetayls opened this issue Feb 26, 2014 · 8 comments

Comments

@davetayls
Copy link
Contributor

I'm not getting an 'error' event when a server call fails. it seems that this line should be calling the error method rather than the success method?

https://github.com/nilbus/Backbone.dualStorage/blob/master/backbone.dualstorage.coffee#L290

@nilbus
Copy link
Owner

nilbus commented Feb 26, 2014

This is by design. Although it failed to persist to the server, the overall dualSync operation was a success, since it persisted locally. To check if the server request failed, you can use the jQuery fail callback (see #67) or check yourCollection.hasDirtyOrDestroyed().

@nilbus nilbus closed this as completed Feb 26, 2014
@davetayls
Copy link
Contributor Author

I see, I can understand that logic although i might be wrong but it seems to handle the following cases as following, which are a bit odd i think

explicit request { local: false } -> check server -> server fail -> no local store -> resolves with success empty collection

or

no local store -> check server -> server fail -> no local store -> resolves with success empty collection

@nilbus
Copy link
Owner

nilbus commented Feb 26, 2014

For your first example, use remote: true instead of local: false, and it will work like you expect. See #12. I would accept a pull request that made these options work in a sensible way.

I don't follow what exactly you mean in your second example by "no local store" and "check server". Could you be more specific?

@davetayls
Copy link
Contributor Author

ah great, i'll try that for the first instance.

The second example is:

  • if you make a request with default settings
  • and there is no local store created because it's the first time you have made a request
  • dualStorage will make a request to the server
  • at that point if the server fails and there is no local store would it still resolve as success?

thanks

@nilbus
Copy link
Owner

nilbus commented Feb 26, 2014

No, in the 2nd example, it will call success with an empty collection, you are right.

Right now I am uncertain whether from what gets stored now if we can distinguish from the data in the local Store between no-previous-successful-fetch and successful-previous-fetch-with-empty-collection. We certainly don't track that explicitly.

If you'd like to look into making it, on ajax error, call the error callback on the first fetch before any data is cached for a Store, I will work with you to get that merged in.

@nilbus nilbus reopened this Feb 26, 2014
@davetayls
Copy link
Contributor Author

Sure, I'll take a look and give it a go

@davetayls
Copy link
Contributor Author

is there already a way of determining whether a local store currently exists?

@nilbus
Copy link
Owner

nilbus commented Mar 3, 2014

Closing in favor of the pull request

@nilbus nilbus closed this as completed Mar 3, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants