Home » RxJS retry() Error Handling Operator

RxJS retry() Error Handling Operator

by Online Tutorials Library

RxJS retry() Error Handling Operator

RxJS retry() operator is an error-handling operator that returns an observable that mirrors the source observable except for an error. If the source observable calls an error, this method resubscribes to the source observable for a maximum of count resubscriptions (given as a number parameter) instead of propagating the error call.

In other words, we can say that the RxJS retry() operator is used to handle and take care of retrying back on the source observable if it finds there any error and then retry according to the input count given. By applying this operator, we hope that if a source observable emits an error, resubscribe to it to ensure that it will be completed without error.


Following is the syntax of the RxJS retry() error handling operator:


Parameter Explanation

retry_count: The argument retry_count is used to specify the number of times we have to retry.

count: It specifies the number of retry attempts before failing. It is an optional operator. Its default value is -1.

Return value

The RxJS retry() operator returns an observable that retry count logic and is modified with the retry logic.

Let us see some examples of the RxJS retry() operator to understand it clearly.

Example 1 (Retry 2 times on error)


After executing the above example, you will see the following result:

RxJS retry() Error Handling Operator

Next TopicRxJS Operators

You may also like