2

I have an application developed with angular 8. It uses httpClient to comunicate with the backend and uses autentication.

I have a weird problem I can find the solution after long research.

I have users all over the world, and it only fails for one of them.

For one particular user and (apparently) randomly, the APIs are rejected, and at least as it's said in the console, because of a preflight CORS issue:

Access to XMLHttpRequest 'myAPIip.com" from origin 'myip.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource

In the console, there is the error:

Error: Uncaught (in promise): EmptyError: no elements in sequence↵

and all this stack trace.

There is no firewal.

Does anybody face similar situation? what can be happening?

cucuru
  • 3,456
  • 8
  • 40
  • 74
  • 1
    That user is most likely receiving a 4xx or 5xx response in those failure cases. And the 4xx or 5xx errors likely doesn’t have the Access-Control-Allow-Origin response header — because 4xx and 5xx errors typically won’t. So because in those cases the browser logs a CORS error to the console but doesn’t also log the 4xx or 5xx status code, it ends up looking like a CORS problem. But in fact it’s a 4xx or 5xx problem. To troubleshoot it, you need to look through the error logs for the myAPIip.com server and see if you find anything there. – sideshowbarker May 19 '20 at 11:23
  • @cucuru did you find a solution? – husnu Feb 06 '21 at 09:41
  • no, it just stop happening without any change in the code, it was quite weird – cucuru Feb 08 '21 at 07:57

3 Answers3

1

FWIW, we were also facing a similar problem. We eventually narrowed it down to the user info containing a unicode character. For example, the user getting the error had a last name similar to:

  • François
  • Sørina
  • Nuñez

The HTTP proxy that we were using couldn't handle such unicode characters. Hope this helps someone in the future.

Vikram Deshmukh
  • 12,304
  • 4
  • 36
  • 38
0

Probably you have an error in routing or RxJS. Link: EmptyError: no elements in sequence

But also i saw this error in some old version browser, which didn't provide Access-Control-Allow-Origin headers. Check user full request.

  • I use "rxjs": "6.5.2", and user with problems uses last version of Chrome. It also happens (also randomly) in Edge and Firefox – cucuru May 19 '20 at 08:18
  • Need more info. Potential problem is: 1. User navigation from module to module(lazy loading) after app is rebuild on server. 2. Some error in handling response that throw this error: "Error: Uncaught (in promise): EmptyError: no elements in sequence↵" – Roman Leliuk May 19 '20 at 08:37
  • Check the request and find this api call in your app and try to simulate error like CORS and check the console. – Roman Leliuk May 19 '20 at 08:46
-1

Check whether your application is blocking certain IP addresses. Might be the issue.

Aakash Garg
  • 10,649
  • 2
  • 7
  • 25