http interceptors to detect if app is on-/offline (has connection to api) in angularjs
<p>I'm looking for a good solution to detect on-/offline status within my app.
The navigator.onLine apprache is not working, at least with current version of chrome, and I think not reliable. 
App location and server endpoint may differ, so what i really want is to check if the server is offline. I don't mind if the user can use google.com. The app might even be working without internet as long as the server is in the network and responding.</p>

<p>My approach is using an interceptor:</p>

<pre><code>$provide.factory('httpOfflineCheckInterceptor', ['$q', '$rootScope', function($q, $rootScope){
    return {
        'response': function(response) {
/** what am I missing here? **/
            return response;
        },
        'responseError': function(rejection) {
            if(rejection.status === -1) {
                $rootScope.appIsOffline = true;
            }
            return rejection;
        }
    }
}]);

$httpProvider.interceptors.push('httpOfflineCheckInterceptor');
</code></pre>

<p>So, for each http request made i check the response. Detecting if the app is offline works fine. 
The tricky thing is, check if the app is online again. 'response', I do cache http request. Status of some responses is 200 even if i'm offline, because they are cached. So cached request or getting templates should be ignored when checking if the app is online again.</p>