victorx
victorx

Reputation: 3569

How to retry only on certain error emitted by the source observable in RxJs

A srcObservable.retry() will catch the error emitted by the srcObservable and resubscribe to the srcObservable regardless of the type of the error. However, on certain scenario, it is wanted to only retry on certain type of error emitted by the srcObservable. Is there a way to do so in RxJs neatly?

Upvotes: 3

Views: 2551

Answers (1)

Brandon
Brandon

Reputation: 39212

Try using retryWhen:

src.retryWhen(function (errors) {
    // retry for some errors, end the stream with an error for others
    return errors.do(function (e) {
        if (!canRetry(e)) {
            throw e;
        }
    });
});

Upvotes: 10

Related Questions