Javascript Rxjs条件错误流
我基本上是在创建一个事务。简化如下: 1) 打个承诺电话。 2) 如果error和error.code==“ConditionalCheckFailedException”,则忽略该错误并继续流而不做任何更改。 3) 如果出现错误,请停止流 下面给我1和3。如果我有某个例外,我想继续流。可能吗? 目前,我有:Javascript Rxjs条件错误流,javascript,error-handling,promise,rxjs,Javascript,Error Handling,Promise,Rxjs,我基本上是在创建一个事务。简化如下: 1) 打个承诺电话。 2) 如果error和error.code==“ConditionalCheckFailedException”,则忽略该错误并继续流而不做任何更改。 3) 如果出现错误,请停止流 下面给我1和3。如果我有某个例外,我想继续流。可能吗? 目前,我有: //... stream that works to this point .concatMap((item) => { const insertions = Rx.Obs
//... 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
因此,
catch
需要一个函数来提供一个新的可观测数据
相反,请使用以下命令:
来源:谢谢-从真实代码翻译而来,遗漏了一个变量。插入是一种承诺,对吗?但不是常规承诺,因为常规承诺没有
map
方法。。。insertions.map
做什么?它与插入的承诺有什么关系?是的,AWS调用在返回时附加了一个.promise()。“insertions”是一个Rx.Observable.fromPromise。查看它,您似乎在错误地使用Observable.catch
。。。i、 e示例不返回Rx.Observable.throw(e)代码>或<代码>返回可观察的Rx.just(42)
尝试使用promisecatch
而不是可观察的,即将调用链接到AwsCall(…)
而不是fromPromise(…)
。从承诺的角度来看,您的代码看起来是正确的
//... stream that works to this point
.concatMap((item) => {
const insertions = Rx.Observable.fromPromise(AwsCall(item))
.catch(e => e.code === "ConditionalCheckFailedException"
? Rx.Observable.of(item)
: Rx.Observable.throw(e)
)
/* depending on what AwsCall returns this might not be necessary: */
.map(_ => item)
return insertions;
})
.concat // ... much the same