Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS HTTP status -1

I'm working on offline handling for a angularjs app with cordova (Android & iOS). I wrote an http interceptor, that checks for the status of an http requests, and decides what to do.

I had a working version some month ago, and suddenly this stopped working. I found out that I was checking for a http status of 0. Now this returns -1, but I don't why.

responseError: function(response) {
   console.log(response.status); // this returns now -1
}

So my questions are:

  • What are the standard http codes for ajax requests that define cases like network unavailable, offline, timeout... everything when the server is not reachable (e.g. when you shut down your server in development, your mobile connection breaks, or is too slow and times out...)
  • Is the status code set by the browser, or manipulated by AngularJS?
  • Are this codes the same across every browser? Desktop & mobile?
  • What is the difference between code 0 and -1?
like image 469
23tux Avatar asked May 30 '26 16:05

23tux


1 Answers

There was a change in the more recent versions of angular, with the handling of http status code 0. Here is a github discussion based on the change.

I hope you have already solved you problem by now!

like image 175
Mr. CatNaps Avatar answered Jun 01 '26 06:06

Mr. CatNaps