[英]Bluebird promise.all catch in mid promise chain and continue with promise
大家好,在此先感谢您的帮助。
以下是我正在尝试做的事情
function1(){
throw some error();
}
function2() {
// dosomething successfully;
}
promise.resolve()
.then()
.then(
// here i want to do promise.all and if there is any exception i want to continue with chain
promise.all(function1, function2)
.catch() // handle error here only
)
.then()
.then()
.catch()
任何人都可以帮助我如何实现这一目标。 即在做promise.all,如果有任何错误。 我不想打破这个承诺链。
尝试:
Promise.resolve().then(()=> {
return Promise.all(promisesArray).catch((err) => console.log(err))
}).then(() => console.log('continue futher'));
如果你有一个.catch()
在Promise.all()
你不从抓投入或不返回拒绝承诺,那么承诺链将继续与任何值.catch()
返回。
它是在try/catch
之后完全建模的,其中catch会停止异常,除非您重新抛出异常。 同样, .catch()
停止拒绝,除非您从catch处理程序中抛出(或返回被拒绝的诺言)。
另外,您的代码流程不太正确。 您在此处使用Promise.all()
方式不正确:
Promise.resolve().then(...).then(Promise.all(...).catch(...)).then(...)
你必须通过一个函数.then()
不调用的结果Promise.all()
这是一个承诺。 当调用Promise.all()
您需要传递一个promise数组。
您可以这样做:
Promise.resolve()
.then(...)
.then(function() {
return Promise.all([funcReturnsPromise1(), funcReturnsPromise2()]).catch(...);
}).then(...)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.