Originally posted here, March 2015
Yesterday someone asked me about using promises in Angular. I explained a little about asynchronous pyramids of doom, and how you can define a callback function to handle the success case and one for the error scenario. Then they asked me what happens when you have a chain, and first call in the chain returns an error response, does the second call execute? Like this:
MyPromise .then(dummyFunc1(successCallback1, errorCallback1)) .then(dummyFunc2(successCallback2, errorCallback2)) .then(dummyFunc2(successCallback2, errorCallback2));I answered that I wasn't sure, but I thought it would stop execution, and probably should stop execution. However when I'm not sure of something, I like to sit down and figure it out. So I built a Plnkr to find out. And no, an error handler does not break the chain. Update: Googling around there are ways to manually code around this issue (if you have a long chain and want to stop execution in the middle). None of them seem particularly elegant. It seems to me there should be a haltOnError event.