Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

angularjs incorrectly returns status 0 on Android when fetching from the application cache #1720

Closed
tokafish opened this issue Dec 18, 2012 · 4 comments

Comments

@tokafish
Copy link

I'm building a mobile web application using AngularJS, and I'm encountering the following issue. My application is cached using an HTML5 Application cache. It loads fine, but if I manually kill the browser (or cause Android WebKit to unload the document), I encounter a problem in $httpBackend:

    function completeRequest(callback, status, response, headersString) {
      // URL_MATCH is defined in src/service/location.js
      var protocol = (url.match(URL_MATCH) || ['', locationProtocol])[1];

      // fix status code for file protocol (it's always 0)
      status = (protocol == 'file') ? (response ? 200 : 404) : status;

      // normalize IE bug (http://bugs.jquery.com/ticket/1450)
      status = status == 1223 ? 204 : status;

      console.log(callback);

      callback(status, response, headersString);
      $browser.$$completeOutstandingRequest(noop);
    }

In the case of loading a file from the appcache (in this case, the template to a particular route for ng-view), status == 0. Because of this, $http rejects the promise instead of resolving it, and the view is never loaded.

I'm wondering if this line could be added after the file protocol check:

      status = (status == 0 && response) ? 200 : status;

This solves the appcache problem correctly, but I'm not sure if that solution exposes another problem.

Thanks!

@RobbinHabermehl
Copy link

You could fix both bugs in one line of code:

// fix status code for file protocol (it's always 0) and 0 status code for http(s) protocol on Android devices
status = (protocol == 'file') ? (response ? 200 : 404) : (response && status == 0 && window.navigator.userAgent.indexOf('Android') !== -1 ? 200 : status);

Also this code targets just Android for the "0" status code.

@btford btford closed this as completed Aug 24, 2013
@btford
Copy link
Contributor

btford commented Aug 24, 2013

As part of our effort to clean out old issues, this issue is being automatically closed since it has been inactivite for over two months.

Please try the newest versions of Angular (1.0.8 and 1.2.0-rc.1), and if the issue persists, comment below so we can discuss it.

Thanks!

@GokulPulsebeat
Copy link

Could anyone tell me what are the various status codes less that -1 (and their meanings) that are normalised to 0?

@gkalpak
Copy link
Member

gkalpak commented May 13, 2016

I don't think they are standard, so it probably depends on the browser. Often they represent network failures or browser-quirks.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants