A little late, but here's how to do it with the new version of rxjs (> 6) I suppose you are trying to automatically retry the network in the event of a failure. This can be achieved in different ways, but here is a very small implementation of RetryWhen () - this operator catches if any errors are generated by the observable, and creates an errorObservable from this. Now, using errorObservable, we can retry for a specified number of attempts for a specific set of errors
For example, retries in the event of a 404 failure are not really needed, but in the case of 500X exceptions, this is really necessary.
DelayWhen - we could use this statement to indicate a timer , observable, which delays the next retry attempt until the time runs out . This also provides the added benefit of linearly increasing the delay between each retry attempt.
iif - using this conditional operator really allows us to filter and execute the necessary observables based on a given condition. You could also give examples in stackoverflow. But I'm going to give a simple illustration, if still
contactMap is a higher-order observable operator, that is, it produces / maps the input / observable to the output of the observable. The reason for using this is that we need to repeat the retry operation in the case of the same failure for the specified number of times, and the best way to restart the operation is through an Observable error. Note that we could use other higher order observable operators, such as mergeMap / switchMap-, each of which has its advantages and disadvantages, but I prefer to use this. Again, ContactMap is different than Concat, so be careful
I believe the best place to implement such a retry in Angular is inside httpinterceptors, but it can also be done inside a service
Here is an example implementation:
Hope this helps ..
UPDATE: There is a really good article on backoff-rxjs that really cuts down on everything we did above. Please refer to this link.