Whenever a CORS $http request fails, the response returned is always 0

前端 未结 1 545
旧巷少年郎
旧巷少年郎 2020-12-11 05:52

this is a similar question to this post in SO.But the answer provided here cannot be applied in my case as i cannot change the response headers from server.

Suppose

相关标签:
1条回答
  • 2020-12-11 06:05

    This is not an issue of AngularJS / $http but it is the behavior of the browsers and their XMLHttpRequest object: If the CORS request fails, the browser does not give any information back to the caller.

    Before I got this understanding, I also though it to be an AngularJS issue and I raised an open issue on github of Angular -> with the corresponding comment.

    https://github.com/angular/angular.js/issues/13085#issuecomment-148047721

    So I think there seems no other way to solve this as to add the Access-Control-Allow-Origin response header also on the proxy / load balancer in case of 503.

    Edit: If your load balancer is a HAproxy, the following may help you too:
    HAproxy: different 503 errorfile for OPTIONS and POST methods
    It shows how to let HAproxy anwer the CORS requests autonomous.

    0 讨论(0)
提交回复
热议问题