Retry failed http req according to a condition, and specify the number of attempts that it should be retried – Angular

  angular, javascript, rxjs, typescript

I’ve a post request that i’m using inside my angular application.
My goal is to check the message inside the error, and according to that retry the request BUT i’d like to retry a certain amount of attempts.

In the beginning i was trying this approach:

public post(url, data) {, data).pipe(
      catchError((err: HttpErrorResponse) => {
        if (err.message === 'something') {
          return EMPTY;

But in this case it was retrying to send the failing req without checking the condition inside catchError.
So i was thinking to use the retryWhen() operator, but here i don’t know how to specify the amount of attempts that should be executed

Source: Angular Questions

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.