Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling a function while angular gives error 'net::ERR_INTERNET_DISCONNECTED'

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.

like image 797
Aditya Ponkshe Avatar asked Mar 13 '26 21:03

Aditya Ponkshe


1 Answers

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

like image 135
Marcus Avatar answered Mar 15 '26 13:03

Marcus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!