3

When I loose net connection and try to load a HTML template(which is not loaded previously) using angularJS it gives me error, net::ERR_INTERNET_DISCONNECTED.

Is there any way to call a function before angular fires error net::ERR_INTERNET_DISCONNECTED , so I will be able to notify user they have lost their connection.

I don't want to put watchers on online/offline status since I want user to be able to see previously loaded HTML templates.

Aditya Ponkshe
  • 3,840
  • 4
  • 39
  • 58

1 Answers1

1

From angularjs docs

angular.module('exceptionOverride', []).factory('$exceptionHandler', function() {
  return function(exception, cause) {
    exception.message += ' (caused by "' + cause + '")';
    throw exception;
  };
});

Use this to catch every exception, including internet connection problems, it all runs through this method

Marcus
  • 341
  • 1
  • 8
  • 1
    can you give a example for this. – Aditya Ponkshe Jan 20 '15 at 08:13
  • "net::ERR_INTERNET_DISCONNECTED" is chrome error, not angular as far as I remember. Insert into method i posted some "online-check", an ajax request for example or "navigator.onLine" condition. You can detect if internet connection has gone down, but I am not sure if you can prevent error from appearing – Marcus Jan 20 '15 at 08:47
  • 1
    I don't want to prevent the error. I just want to know if the template is going to loaded or not. If not I will show something to user. Like I said in the question itself I don't want to do that on the basis of internet connection as user should be able to see the pages which are in the cache. – Aditya Ponkshe Jan 20 '15 at 08:50