angular - Preflight CORS request fails intermittently - Stack Overflow

admin2025-04-09  1

I am developing a web app which fetches data from a backend API server. Most of the times, this is successful. Sometimes the preflight request fails with the following error -

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://<some-backend-server>. (Reason: CORS request did not succeed). Status code: (null).

This issue is only observed on Firefox and not on other browsers. And typically only seen when my laptop starts after going to sleep. Another thing I noticed is that on browser console in network tab, when I switch to raw request headers, all the requests to the above endpoint which are successful shows up like this - OPTIONS /<endpoint> HTTP/1.1.

Whereas all the requests that fail show up like this - OPTIONS /<endpoint> undefined

Edit 1 - Further investigation of backend proxy logs suggest that when the request is failing, the call is not reaching backend at all.

I am developing a web app which fetches data from a backend API server. Most of the times, this is successful. Sometimes the preflight request fails with the following error -

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://<some-backend-server>. (Reason: CORS request did not succeed). Status code: (null).

This issue is only observed on Firefox and not on other browsers. And typically only seen when my laptop starts after going to sleep. Another thing I noticed is that on browser console in network tab, when I switch to raw request headers, all the requests to the above endpoint which are successful shows up like this - OPTIONS /<endpoint> HTTP/1.1.

Whereas all the requests that fail show up like this - OPTIONS /<endpoint> undefined

Edit 1 - Further investigation of backend proxy logs suggest that when the request is failing, the call is not reaching backend at all.

Share Improve this question edited Mar 25 at 12:31 VinayakaB asked Mar 25 at 10:37 VinayakaBVinayakaB 736 bronze badges 3
  • Are you sure you are not being rate limited? – reynaldi Commented Mar 25 at 11:36
  • Yes. I own the backend server as well. – VinayakaB Commented Mar 25 at 12:30
  • See here: developer.mozilla./en-US/docs/Web/HTTP/Guides/CORS/Errors/… When the reason is listed as "CORS request did not succeed" it means there was a problem with the request/response. (might just be a problem with Wifi, your ISP, etc...) – browsermator Commented Mar 25 at 19:20
Add a comment  | 

1 Answer 1

Reset to default 0

As the issue is only observed on Firefox, it may be imposing a strict same-origin-policy, I think the fix for this will be to enable CORS in the angular application.

you may refer to this thread

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1744203526a235913.html

最新回复(0)