我实际上是在创建一个交易。简化将描述如下:
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
答案 0 :(得分:1)
所以catch
想要一个提供新Observable的函数。
相反,使用此:
//... 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
来源:http://reactivex.io/rxjs/class/es6/Observable.js~Observable.html#instance-method-catch