yayitswei yayitswei - 1 month ago 6
AngularJS Question

How to return a failed promise?

How would I return a promise but invoke its failure block immediately? Here's a gnarly way to do it:

if (fail) {
var q = $q.deferred();

$timeout(function() {
q.reject("")
}, 1);

return q.promise;
} else {
return $http.get("/").then(function(data) {});
}

Answer Source
if( fail ) {
    return $q.reject(yourReasonObject);
}
else ...

Ref here :)