如何在错误后停止调用 promise 链中的所有方法
How to stop all methods in promise chain from being called after an error
promise
.catch(e => { console.log('Error'); return; })
.finally(e => { console.log('Hi Mum'); return; })
.then(e => { console.log('hello'); return; });
当 promise 被拒绝时,then
方法仍然被调用。
如何在拒绝后停止调用 then
方法?
您调用 then
来晚了* 您应该在捕获之前调用它:
promise
.then(e => { console.log('hello'); return; });
.catch(e => { console.log('Error'); return; })
.finally(e => { console.log('Hi Mum'); return; })
Promises 形成一条链,抓到东西后继续是完全有效的。
*:太晚了,我的意思是 then
处理程序注册为从 finally
返回的 Promise 的延续,而不是初始 Promise。
promise
.catch(e => { console.log('Error'); return; })
.finally(e => { console.log('Hi Mum'); return; })
.then(e => { console.log('hello'); return; });
当 promise 被拒绝时,then
方法仍然被调用。
如何在拒绝后停止调用 then
方法?
您调用 then
来晚了* 您应该在捕获之前调用它:
promise
.then(e => { console.log('hello'); return; });
.catch(e => { console.log('Error'); return; })
.finally(e => { console.log('Hi Mum'); return; })
Promises 形成一条链,抓到东西后继续是完全有效的。
*:太晚了,我的意思是 then
处理程序注册为从 finally
返回的 Promise 的延续,而不是初始 Promise。