I have this situation where I need to make a get request. I do know how to use Angular's http client, but I need to make the request retry automatically if it fails, for a number of times before giving up and throwing an error, and also I need to put a delay between each retry.
For example, I need my request, if it fails, to retry for a total of 5 times, and between each retry have 10 seconds delay.
Is there an easy and clear way to do something like that?
I have the same need in my angular app, so I created a pipeable operator called retryWithBackoff. It uses exponential backoff, so the time between retries looks like:
It can be used very simply:
Here is the operator:
It will timeout in 12 seconds, regardless of how many attempts have been made. The two exceptions it can throw are just an empty custom exception class:
I also have some incomplete jasmine tests for it: