Ignore errors in Observable and Continue

时间:2018-02-22 04:30:15

标签: rxjs

How to do some action if error happen in stream, but continue to receive new items? For example, I need to just logging error, but continue to receive data from server. I tried a lot of solutions from stackoverflow, but stream always behave like closed.

1 个答案:

答案 0 :(得分:1)

The solution is quite easy:

const frontendMessagesStream = new Subject<FrontendMessage>()
frontendMessagesStream
    .pipe(
        tap(console.log),
        map(someThrow),
        tap(console.log),
        catchError((err, o) => o), // the second parameter will be your observable. It replaces your stream.
    )
    .subscribe()