Why does the second then() has its done handler called instead of the fail one?
Let's look at how your code looks in the synchronous world:
var value;
try{
try {
throw new Error("buuu!");
console.log("First handler: Done!: Argument: ");
value = "First then: DONE";
} catch(e){
console.error("First handler: Fail!. Argument: ", e);
value = "First then: FAIL";
}
console.info("Second handler: Done!. Argument: ", value);
}catch(e){
console.error("Second handler: Fail!. Argument: ", e);
}
When you handle an error in a catch
clause, just like when you handle an error in a then
clause, you recover from it. The promises example is exactly like our synchronous one.
If you want to signal that you performed your recovery logic but are still in a rejected state on the chain, rethrow. That's how it's always done in synchronous code.