determine request time out in angular $http

angularjs

Solution

I have done it as below...

var startTime = new Date().getTime();
$http.post(...)
    .success(function(resp, status, header, config) {...})
    .error(function(resp, status, header, config) {
        var respTime = new Date().getTime() - startTime;
        if(respTime >= config.timeout){
            //time out handeling
        } else{
            //other error hanndling
        }
    });

Problem

I am sending an http request using angular as below. ``` $http({ url: url, params: params, method:'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' }, timeout: 60000 //60 seconds }).success(function(data, status, headers, config) { //do something }).error(function(data, status, header, config) { if(timedout){ //determine occurrence of timeout. //invoke timeout handler } else //handle other error } }); ``` How can I determine the timeout? I have observed that status code "0" is received in this case. Is it safe to check status==0 for timeout? Please note that I am not asking about HTTP Request timeout (status code 408).

Original source