Inside an HTTP call, I am checking for the response
promise.then(function(res){
var value = null;
var keepGoing = true;
for(var key in res) {
if(keepGoing){
//If the response object has a null value for any of the given keys, we assume the API has failed
if(value === null)
keepGoing = false;
}
}
//And we reject the promise
if(!keepGoing){
$q.reject("Bad data");
}
//Else, we loop through the keys
if(res.length != 0){
var keysArray = Object.keys(res);
....
....
},function(error){
vm.continuing = false;
vm.errorInContinue = true;
});
What I want that whenever I reject that promise, do not execute the next lines and jump to the error block.
What am I doing wrong?
I tried return $q.reject("Some bad data")
also, but did not help.