$ q.reject无效并返回Angular中的错误块

时间:2017-09-20 13:30:47

标签: angularjs promise

在HTTP调用中,我正在检查响应

   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;
    });

每当我拒绝承诺时,我想要的是,不要执行下一行并跳转到错误块。

我做错了什么?

我也试过return $q.reject("Some bad data"),但没有帮助。

0 个答案:

没有答案