RxJs catch error and continue

后端 未结 4 945
臣服心动
臣服心动 2020-12-08 08:58

I have a list of items to parse, but the parsing of one of them can fail.

What is the \"Rx-Way\" to catch error but continue executing the sequence

Code Samp

4条回答
  •  一生所求
    2020-12-08 09:50

    To keep your endlessObservable$ from dying you can put your failingObservable$ in a higher-order mapping operator (e.g. switchMap, concatMap, exhaustMap...) and swallow the error there by terminating the inner stream with an empty() observable returning no values.

    Using RxJS 6:

    endlessObservable$
        .pipe(
            switchMap(() => failingObservable$
                .pipe(
                    catchError((err) => {
                        console.error(err);
                        return empty();
                    })
                )
            )
        );
    

提交回复
热议问题