【发布时间】:2017-05-19 03:34:01
【问题描述】:
我实际上是在创建一个事务。简化如下:
1) 进行承诺电话。 2) 如果 error 和 error.code === "ConditionalCheckFailedException",忽略错误并继续流而不做任何更改。 3)如果错误,停止流。
下面给我 1 和 3。如果我有某个例外,我想继续直播。那可能吗? ...
目前,我有:
//... stream that works to this point
.concatMap((item) => {
const insertions = Rx.Observable.fromPromise(AwsCall(item))
.catch(e => {
if (e.code === "ConditionalCheckFailedException") {
return item
} else {
throw e;
}
});
return insertions.map(() => item);
})
.concat // ... much the same
【问题讨论】:
-
谢谢 - 正在从真实代码翻译并遗漏了一个变量。
-
insertions 是一个承诺,对吧?但不是常规承诺,因为常规承诺没有
map方法......insertions.map做什么?它与insertions的承诺有何关系? -
是的,AWS 调用在返回时附加了一个 .promise()。 “插入”是一个 Rx.Observable.fromPromise。
-
看着this documentation,您似乎错误地使用了observable
.catch...即示例使用return Rx.Observable.throw(e);或return Rx.Observable.just(42); -
尝试使用承诺
catch而不是可观察的承诺,即将调用链接到AwsCall(…)而不是fromPromise(…)。从承诺的角度来看,您的代码看起来是正确的
标签: javascript error-handling promise rxjs