简体   繁体   中英

Rxjs condition error flow

I'm essentially creating a transaction. A simplification would be described as follows:

1) Make a promise call. 2) If error and error.code === "ConditionalCheckFailedException", ignore the error and continue the stream with no changes. 3) If error, stop stream.

The following give me 1 and 3. I would like to continue on with the stream if I have a certain exception. Is that possible? ...

At the moment, I have:

//... 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

So catch wants a function which delivers a new Observable.

Instead, use this:

//... 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

Source: http://reactivex.io/rxjs/class/es6/Observable.js~Observable.html#instance-method-catch

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM