对于下面的示例,将违反附加条件promise/no-nesting
:
return foo()
.catch(handleErrorAndReject('foo'))
.then(() => bar().catch(handleErrorAndReject('bar')))
.then(() => baz().catch(handleErrorAndReject('baz')))
请注意handleErrorAndReject是一个类似以下的咖喱函数:
const handleErrorAndReject = action => error => {
console.warn(`${action} fails with error`, error)
res.status(400).send(error.message).end()
return Promise.reject(error)
}
但是在这种情况下,嵌套捕获似乎是必需的,因为它们会因阶段而异。是在这种情况下,我应该只eslint-disable
,还是有更好的方法来构造此代码?