问美元.当有一个被拒绝的承诺时,一切都解决了
$q.all resolves when there is a rejected promise
我试图在同一时间执行所有的承诺,所以我可以做一些事情,当他们解决。有一个(强制)拒绝的承诺,但'$q.all()'解决了。我少了一些$q。所有的行为吗?
提前感谢!
function saveOrder () {
return ordersSrv.saveOrder(order).then(function(data) {
console.log('saveOrder OK');
},
function(error) {
console.log('saveOrder KO');
});
}
var aPromises = [saveOrder()];
$q.all(aPromises).then(function () {
console.log('OK');
},
function (error) {
console.log('---> error');
});
在try - catch块中,当你catch
一个错误并且不重新抛出它时-它被处理:
try {
throw Error();
} catch (e) {
console.log("Error", e);
}
console.log("This log also happens");
承诺也是如此:
Promise.reject(Error())
.catch(e => console.log("Error", e))
.then(() => console.log("This log also happens"));
你给你的saveError
拒绝添加一个catch处理程序——这意味着你正在处理它。如果您想要记录但仍然无法处理它-重新抛出它:
try {
throw Error();
} catch (e) {
console.log("Error", e);
throw e;
}
console.log("This log doesn't happen");
或与承诺:
Promise.reject(Error())
.catch(e => { console.log("Error", e); throw e; })
.then(() => console.log("This log doesn't happen"));
相关文章:
- 如何在解决承诺之前和之后验证值
- EmberJS:在成功处理请求时解决承诺
- 蓝鸟没有正确解决承诺
- 使用 $http.post 和 res.redirect,而不解决承诺
- 如何在解决承诺后从承诺对象获取值
- 在解决承诺 AngularJS/ES6 后检索存储在服务中的数据
- CSV 完成读取后,如何解决承诺
- 茉莉花间谍和解决承诺
- 如何在轮询时不断解决Q承诺
- 拒绝并解决Q承诺
- 基于另一个承诺解决承诺
- 立即解决承诺
- 通过离子/ui路由解决承诺
- 我可以选择只在if语句的一部分中解决承诺吗
- 开玩笑-在测试前解决承诺
- 多次解决承诺
- 让双方都期待解决承诺
- 问美元.所有这些都在解决承诺之前被调用
- 在angular中解决承诺
- Angularjs单元测试解决承诺