我有一个 promise 链,我在其中使用 catch 来捕获错误。
this.load()
.then(self.initialize)
.then(self.close)
.catch(function(error){
//error-handling
})
如果链条在没有被拒绝的情况下完成,会调用什么函数? 我终于使用了,但是如果发生错误也会调用它。 我想在 catch 函数之后调用一个函数,该函数仅在没有 promise 被拒绝时才被调用。
我将 node.js 与 q - 模块一起使用。
最佳答案
再添加一个即可。
this.load()
.then(self.initialize)
.then(self.close)
.then(function() {
//Will be called if nothing is rejected
//for sending response or so
})
.catch(function(error){
//error-handling
})
关于javascript - 如果没有被拒绝, promise 链式结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32689844/