I'm just testing the timeout functionality with Angular's $http module, however it keeps returning undefined as the response
It's fine if set up just like this, but if I tack on .error(function)
instead of .then(function)
, to the $http
call, it throws an error trying to grab the data field from an undefined object
var timeout = $q.defer();
var config = {
url: 'http://192.168.1.65:3000',
timeout: timeout.promise,
method: 'POST'
};
$http(config).then(function(res) {
// This is always undefined when timeout occurs
console.log(res);
});
$timeout(function() {
console.log('resolving the promise to abort the http call. This works fine');
timeout.resolve();
}, 1000);
Any ideas what I'm doing wrong?