jpillora / xdomain

A pure JavaScript CORS alternative
https://jpillora.com/xdomain/
3.12k stars 270 forks source link

Failing to load proxy.html should abort the underlying XHR #84

Closed mabotofu closed 10 years ago

mabotofu commented 10 years ago

I'm using angularjs and xdomain. Everything is working but when the proxy.html doesn't exist or fails to load, all requests to the domain just hangs and says:

 xdomain (http://localhost:9000): Timeout waiting on iframe socket 

This is fine and expected but the Angular's promise object doesn't resolve or reject so nothing happens.

Example:

After

GET http://someexternaldomain.com/proxy.html 502 (Bad Gateway) 
$http({
  url: "http://someexternaldomain.com"
})
.then(function (res) {
    console.log("success");
})
.catch(function() {
    console.log("error");
})
.finally(function() {
  console.log("complete");
})

It will say

xdomain (http://localhost:9000): Timeout waiting on iframe socket 

Then, no logs will show. It should at least says "error".

If I remove the domain from the xdomain setup, it will go to the catch and finally. Is this a xdomain issue or Angular is doing something weird?

Thank you

jpillora commented 10 years ago

This is XDomain. Since its taking control of XMLHttpRequest, Angular just thinks it's still loading. I could detect the timeout and abort the XHR - that way the catch will actually fire. Will edit this issue and file it as a bug. Not sure when I'll get time for this though...

mabotofu commented 10 years ago

No worries. I can just wrap the request with a new promise object and force it to reject after a few seconds. Everything else is working fine. XDomain is great. Thank you for your great work!

jpillora commented 10 years ago

Glad it's being of use :)

On Wed, Jun 11, 2014 at 2:07 AM, Naomi Suzuki notifications@github.com wrote:

No worries. I can just wrap the request with a new promise object and force it to reject after a few seconds. Everything else is working fine. XDomain is great. Thank you for your great work!

— Reply to this email directly or view it on GitHub https://github.com/jpillora/xdomain/issues/84#issuecomment-45634824.

jpillora commented 10 years ago

In the angular example, I've modified the request to:

      $http.get('http://echo.jpillora.com/foo/bar/status/500').then(function(result) {
        $rootScope.output = result.data;
      }).catch(function() {
          console.log("error");
      }).finally(function() {
        console.log("complete");
      });

and it correctly prints "error". will close. reopen if it's happening. it could be an angular version issue...