Try this piece of code on console tab of Chrome or Firefox
var p = new Promise(function(resolve, reject) {
setTimeout(function() {
reject(10);
}, 1000)
})
p.then(function(res) { console.log(1, 'succ', res) })
.catch(function(res) { console.log(1, 'err', res) })
.then(function(res) { console.log(2, 'succ', res) })
.catch(function(res) { console.log(2, 'err', res) })
The result will be
1 "err" 10
2 "res" undefined
I've tried many other examples but it seems that the first then()
returns a promise that always resolves and never rejects. I've tried this on Chrome 46.0.2490.86 and Firefox 42.0. Why does this happen? I thought that then()
and catch()
can be chain multiple times?