I'm trying to handle errors with my resources, and then handle rejection of resources in my $q.all()
.
我尝试使用我的资源处理错误,然后处理$q.all()中的资源拒绝。
This is my code:
这是我的代码:
var user = User.get({id: 1}, function() {
// Success
}, function(response) {
// Error
return $q.reject(response);
});
var promiseList = [user];
$q.all(promiseList).then(function(){
// Success <-- this seems to run all the time
}, function(response) {
// Error <-- this never seems to run but I want it to
});
When my User resource receives a 404, the error callback handles it and returns a $q.reject
.
当我的用户资源收到404时,错误回调处理它并返回$q.reject。
However the success callback in my $q.all
gets called, not my error callback. I would've thought because I am rejecting my promise the $q.all
error callback would be fired?
但是成功回调在我的$q。所有的都被调用,而不是我的错误回调。我可能会想,因为我拒绝了我的承诺。所有的错误回调将被触发?
I appreciate I only have 1 item in my promiseList
but that shouldn't make a difference should it?
我很感激我的承诺中只有一项,但这不应该有什么不同,是吗?
1 个解决方案
#1
12
According to Michael in the comments
根据Michael的评论
I changed
我改变了
var promiseList = [user];
To this:
:
var promiseList = [user.$promise];
And now the $q.reject()
is being picked up by the $q.all()
.
现在$q.reject()被$q.all()接收。
Awesome, thanks for the advice.
太棒了,谢谢你的建议。
#1
12
According to Michael in the comments
根据Michael的评论
I changed
我改变了
var promiseList = [user];
To this:
:
var promiseList = [user.$promise];
And now the $q.reject()
is being picked up by the $q.all()
.
现在$q.reject()被$q.all()接收。
Awesome, thanks for the advice.
太棒了,谢谢你的建议。