How to get the underlying reason of ajax error 0

I have a ionic APP on sale. My customer complain to me that they often encounter “server can not reach” error, especially at the first time they open the APP after app is closed for hours. If they re-try, then app works.

I checked the log at server side, but find nothing special.
I checked the font-sized code, angular $http returns error with state 0.

state 0 means a lot, it can be CORS issue, DNS issue, or even server shutdown. If I can reproduce the issue locally in the web browser, then the browser can tell me the error detail in the console. But now the issue occur in some customer’s phone, I can get nothing.

So my question is: Can I get the underlying reason of error 0 in javascript layer? So that I can log it.

After some research, it seems we can not know the underlying reason of ajax error 0 from js layer.
Some is there anything else I can try?

status 0 is in most cases on clientside and thrown by the browser/webview.

Like you manually cancel a request, your request takes longer than the default timeout in angular (10sec i think).

Because CORS is in general a serverside configuration.
If the backend is not reachable you should get a 502 or 503 i think.
And for cors it should be 403 or sometimes 404.
But if you have configured the whitelist plugin correctly you will never run into this in your apps.

Status 0 does not give you more information.

@bengtler according to my research, CORS issue, DNS issue, or even server shutdown, they all make you get state 0.

You can check this question on stack overflow for more detail:

If i have cors issues i get:
Failed to load resource: the server responded with a status of 403 (Forbidden)

XMLHttpRequest cannot load http://xxxxxx. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http:/xxxxx' is therefore not allowed access. The response had HTTP status code 403.

from the server in google chrome.

DNS error is not an internet thing more a network issue --> so the browsers cancels the request. If the server is unreachable --> there is no connection to it, in most cases you run into a request-timeout (canceled by your browser after a specific time).

Or if you have no network connection --> it is directly canceled.

So this are all clientside issues and because of that you can not distinguish them.

Only thing you can check is, if you have correct internet connection --> so it must be a server problem like not online or to busy