I'm having trouble with chaining .then()
calls for a promise. When executing the following code:
var prom = new Promise(function(resolve, reject) {
//let's always fail
reject(Error("buuuu!"));
});
var thenable =
prom.then(
function(done) {
console.log("First handler: Done!: Argument: ", done);
return "First then: DONE";
},
function(fail) {
console.error("First handler: Fail!. Argument: ", fail);
return "First then: FAIL";
}
).then(
function(done) {
console.info("Second handler: Done!. Argument: ", done);
},
function(fail) {
console.error("Second handler: Fail!. Argument: ", fail);
}
);
This prints the following in the console:
First handler: Fail!. Argument: Error {stack: (...), message: "buuuu!"}
Second handler: Done!. Argument: First then: FAIL
Why does the second then()
has its done
handler called instead of the fail
one?
Is this a bug with Chrome? (Note that I'm only interested in Google Chrome's behavior)
Do I need to resort to returning pre-resolved/rejected Promises from the .then
handlers?