0

I am using Angular HttpClient in a Ionic 3 App. I also used RxJs operators as a wrapper for my http request.

Here is my code below:

getDriverMeInfo() {
    return this.http.get(`${this.global.baseUrl}/me`)
    .retryWhen(e => e.do(err => { if (err instanceof HttpErrorResponse) console.log(err) }) 
    .delay(10000).take(10) // Delay after 10 seconds when an error occured and retry maximum of 10 takes
    ).toPromise()
  }

I call this function every time that app has successfully booted or loaded. The function retries when an error occured. What I want to happen is how would I know if the http request has reached 10 retries in the take method?

Appreciate if someone could help. Thanks in advance.

KnowledgeSeeker
  • 1,058
  • 2
  • 19
  • 44
  • No matter how many times it retries. It will only ever emit a single value, because `http.get` only emits a single value. So `take(10)` has no effect. – Reactgular Sep 12 '18 at 01:28
  • Possible duplicate of [How to create an RXjs RetryWhen with delay and limit on tries](https://stackoverflow.com/questions/44911251/how-to-create-an-rxjs-retrywhen-with-delay-and-limit-on-tries) – Reactgular Sep 12 '18 at 01:29
  • @cgTag thanks! It is working now. But there is a little problem. I am not able to catch the error on the caller of the function. The error logs only shows up automatically without any catch even thou I called the function without catch – KnowledgeSeeker Sep 12 '18 at 03:33

0 Answers0