0

There is an API where the HTTP request has been sent and there is no response for a long time but when the user refreshes the page the API responds immeditally this behavior occurs often, so I want to use RXJS to overcome this issue. when the API does not respond within 40 seconds it should automatically retry the HTTP request & it should be attempted 3 times. how to achieve this behavior using RXJS

Here is the code:

ABC.service.ts

 getABC() {
    return this.http
      .get(.........)
      .pipe(
        map(responseData => {
          return responseData
        }),
        catchError(errorRes => {
          return this.handleError(errorRes);
        })
      );
  }

XYZ.component.ts

  this._abcService.getABC().subscribe((res: any[]) => {
     console.log(res);
    }, error => {
      console.log(error);
    });

Help me with this Issue

santosh
  • 192
  • 9

1 Answers1

0

Please have a look at the solution already posted here:

https://stackoverflow.com/a/50678363/2976617

You only need to adjust the time for the timeout and the number of retries.

daflodedeing
  • 319
  • 3
  • 11