【发布时间】:2017-09-18 17:19:21
【问题描述】:
我希望promise catch 块不会使promise 失败,我只想在它没有成功时返回false!我该怎么做?
我尝试将拒绝包装在 try catch 块中,但没有成功。
https://jsfiddle.net/2fz69ea2/1/
var passing_promise = new Promise(function(resolve, reject) {
resolve('Success');
});
// I want this function to just return false,
var failing_promise = new Promise(function(resolve, reject) {
reject('Failure');
})
.then(() => {
return true;
})
.catch(() => {
return false;
})
passing_promise.then(()=>{
return failing_promise()
}).then((ret) => {
console.log('please print false.. please! ', ret)
})
.catch(() => {
console.log('I Never want to make it here, but as it stands I do')
})
我也想知道这是否意味着我在滥用承诺。请帮忙!
【问题讨论】:
标签: node.js ecmascript-6 promise