Angular/HTTP: Canceling requests with timeout promise does not work
Closed this issue · 0 comments
This bug was found while trying to address the problem of how to cancel a request made with js-data in Angular.
At one point, it was suggested to pass a promise as the timeout
property in the options to findAll
, since that's the mechanism that Angular provides for canceling requests made with $http. However, this is not canceling the callback after the timeout promise is resolved.
I dug into it, and the reason it's not doing it is because js-data-http's findAll
and HTTP
methods start out by doing a copy
on the config. That deep copy clones the timeout promise, and so resolving the original timeout promise doesn't resolve the clone.
I tried modifying the code in the js-data-angular dist to see if creating a shallow copy (using _.clone
) instead of a deep copy (copy
from JSUtils) in findAll
and HTTP
would fix the issue, and it worked for findAll
at first glance. However, it seems that other methods besides findAll
would have the same issue, and when I replaced copy
with _.clone
in find
, I got this error:
Error: organizations.inject: "attrs" must contain the property specified by "idAttribute"!
So it appears that there's something else going on at a different level that could prevent a shallow clone from working generically across the different methods. I'm not sure what.
Another approach that would fix this specific issue, would be to have the copy
code check to see if the source
argument is a Promise (not sure how to do that 100% correctly yet), and copy it by reference if so.