Answer the question
In order to leave comments, you need to log in
How to properly recognize $http error in AngularJS?
There was a following problem.
Angularjs uses $http.post to load data from the server. In the case when the data source (its own API) is not available for some reason (well, or there is no Internet), $http returns status = 0 in the error handler. Which is fine. Having received this status, I want to inform the user about problems in the network or API. However, the same status is assigned to the request in the case when there is simply a transition to another page with an interruption, respectively, of the current ajax request (there is such bad luck). And, of course, in this case, there is no need to issue any frightening messages to the user.
The question is whether it is possible to separate flies from cutlets, i.e. to recognize the interruption of the request by the user and the real unavailability of the remote source?
Answer the question
In order to leave comments, you need to log in
Most browsers have events offline, online - https://developer.mozilla.org/en-US/docs/Web/API/N... you can track their status.
Use the error method and status.
$http.post(...).
error(function(data, status) {
if(status == 404) {
alert('Not found');
}
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question