Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

capture "no internet connection" in AngularJS

I would like my AngularJS app to capture "no internet connection" just like how Chrome captures it. When Chrome captures it, it shows net::ERR_INTERNET_DISCONNECTED on the console.log.

Angular's HTTP interceptor is not able to capture it. The only data I get is rejection.data.status undefined rejection.status 0

like image 482
devwannabe Avatar asked Dec 20 '22 06:12

devwannabe


1 Answers

So far, this has been working great. I noticed that the status is 0 when it can't contact anything. This is inside my http interceptor

responseError: function (rejection) {
    if (rejection.status == 0) {
        // put whatever behavior you would like to happen
    }
    // .......
    return $q.reject(rejection);
}
like image 174
devwannabe Avatar answered Dec 21 '22 18:12

devwannabe