Closed edoroshenko closed 10 years ago
If you need to propagate error through chain, you should either throw exception from onError
handler or return rejected promise. Otherwise it's assumed that onError
handler has processed error.
See specification: https://github.com/promises-aplus/promises-spec
So, am I correct, if I say, that i shouldn't want to chain calls of promise methods?
No, you aren't.
promise
.fail(function(e) {
...
throw e; // or return vow.reject(e);
})
.fail(function(e) {
// this callback will be invoked
});
If I want to chain fail
calls, I must throw an exception in each of them. True?
Yes, you should propagate error in each callback if you need. The point is that you can handle error and turn chain to the success case.
ok, understood. Thanks!
If I chain calls of method
then
like thisboth
onSuccess1
andonSuccess2
are called. And it's an expected behaviour. If I chain calls of methodfail
like thisor do something like this
then only
onError1
is called. And it's an unexpected behaviour. This hurts, when you return Vow.Promise from function. You can't write something like thisSo, while chaining works expectedly only for method
then
, you should not use chaining at all to prevent remembering complicated rules.