-
Notifications
You must be signed in to change notification settings - Fork 76
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
caching failed remote fetches? #284
Comments
Just found the cacheError option in the fetch options of the store. When I set it to EDIT: I mean setting cacheError to false. |
Hey, are you using Marty v0.8? We removed automatically converting http responses >= 400 in v0.9 |
I am using Marty 0.9 |
Any ideas @jhollingworth ? |
Hey, sorry been on holiday. I'm flying back today, will have a look at this properly when I get back
|
No worries. I appreciate the hard work you have put into this library. |
Since Ive opened the bug, I switch to axios and same issue. |
@bishtawi Another thing to try is catching the error returned this.fetch({
locally() {
...
},
remotely() {
return UserAPI.getUser(123).catch(function (error) {
console.log('Failed to get user', error);
});
}
}) |
Maybe i am setting up my stores, queries or sources wrong. Here is what I have: Store:
queries:
sources:
Using axios shouldnt matter as I have had this bug back when I was using fetch. The variable type that I am passing around is just a string. |
Setting cacheError to false results in a never ending stream of requests to my server. It just keeps sending requests. I have to exit the page to stop it. I can see the requests being made using chrome dev tools. EDIT: I should say that it only keeps sending requests when my server is down. If the server is up, it doesnt continuously send requests. I am using Marty 0.9.11. |
Your code looks fine, this is probably due to an action being dispatched after the fetch failed which causes the component to re-start the fetch and thus creating the loop. If you have a chance could you debug in devtools and see what action is causing the component to re-render? |
I am about to go to bed, so I'll do some more debugging tomorrow. In the mean time, heres my container:
|
Interesting, can you try commenting out this block of code and see if that makes a difference? (You might need to re-build if you aren't using browserify) |
Nope, does not make a difference. |
Hey, I had the exact same problem as OP, but I managed to find the cause of the problem in the Marty source files. I am not sure if this solution is perfect or anything, but it fixed the problem for me. Check out the highlighted line in the link. It caused my container to run the fetch method of my store in an endless loop, because it emitted a store change on every failed fetch. In order to prevent this from happening, I've added a short if statement to check if the cacheError option was set to false and killed the execution of the hasChanged method. What do you think of this solution? I am not 100% sure that it doesn't break in other use cases. :/ Thanks for your awesome library btw. ;) |
@jhollingworth What do you think of Pytal's solution? |
Got the same problem, infinite requests if cacheError is false. ´´´ |
Updated link for #284 (comment): https://github.com/martyjs/marty/blob/v0.9.17/lib/store/fetch.js#L95, or https://github.com/martyjs/marty-lib/blob/master/src/store/storeFetch.js#L94 for v10. That The thing is - the store has to have a value to pass down to the container. If you're not caching errors, and the request fails, what value is the container supposed to receive? It has to be fed something. |
I guess the right thing to do here would be to change the behavior of |
I'm seeing this in v0.10. Could be related to this. |
I have a http source that makes a simple GET to my server to get some data into my store. If my server returns an error (404, 500, etc), I noticed that the store caches the error so any additional attempts to fetch the data auto fails (it doesnt even bother going back to the server). I would like to be able to rehit the server the next time my component attempts to fetch data from the store (on the off-chance that the server is back up).
The text was updated successfully, but these errors were encountered: