How to create an RXjs RetryWhen with delay and limit on tries

Viewed 21358

I am trying to make an API call (using angular4), which retries when it fails, using retryWhen. I want it to delay for 500 ms and retry again. This can be achieved with this code:

loadSomething(): Observable<SomeInterface> {
  return this.http.get(this.someEndpoint, commonHttpHeaders())
    .retryWhen(errors => errors.delay(500));
}

But this will keep trying forever. How do I limit it to, let's say 10 times?

Thank you!

2 Answers
Related