How to display timeout error in angular js $http calls? How to display timeout error in angular js $http calls? angularjs angularjs

How to display timeout error in angular js $http calls?


And if you want to do someting when connection timed out for every request, you can use interceptors (global timeout param doesn't work) :

// loading for each http requestapp.config(function ($httpProvider) {    $httpProvider.interceptors.push(function ($rootScope, $q) {        return {            request: function (config) {                config.timeout = 1000;                return config;            },            responseError: function (rejection) {                switch (rejection.status){                    case 408 :                        console.log('connection timed out');                        break;                }                return $q.reject(rejection);            }        }    })})


You can use angular interceptor to achieve this.

$httpProvider.responseInterceptors.push(['$q', '$injector','$rootScope', function ( $q, $injector,$rootScope) { return function (promise) {    return promise.then(function (response) {        return response;    }, function (response) {        console.log(response); // response status        return $q.reject(response);    });  }; }]);}]);

More info see this link