【发布时间】:2013-11-04 22:59:26
【问题描述】:
我终于得到了 Angular promise 错误处理,但这对我来说是违反直觉的。我预计错误将由失败回调处理,但我不得不使用 catch。
我不太明白为什么要执行 catch 而不是失败回调。
我的预期:
SomeAsyncService.getData().then(function (result) {
// The call is successful.
// Code in this block throws an error.
}, function (error) {
// I expected to handle errors here.
});
什么最终奏效了。
SomeAsyncService.getData().then(function (result) {
// The call is successful.
// Code in this block throws an error.
}).catch(function (error) {
// Where the error is actually caught.
});
如果有更合适的方式来处理 promise 错误,请告诉我。
【问题讨论】: