Promise Failure
doSomething()
.then(function (result) {
return doSomethingElse(result);
})
.then(function (newResult) {
return doThirdThing(newResult);
})
.then(function (finalResult) {
console.log("Got the final result: " + finalResult);
})
.catch(failureCallback);
Another nice thing they do is return errors if they’re passed one. So errors propagate down the chain the way they would down the stack and you can handle them once at the end.
Here if any one of the functions fails you will hit the failureCallback.