1

I have this code that work as intended:

  • i dispatch a signin function
  • the effect take data fom action and make http post
  • if the error status is 504 i retry the http post
  • if it's all ok -> success action else error action
authSignIn$ = createEffect(() => this.actions$.pipe(
    ofType(authActions.signInStart),
    exhaustMap(action => this.http
      .post<responseModel.SignInResponse>(`${environment.baseUrl}/${authBaseUrl}/${ApiPaths.singIn}`, {
        codF: action.username,
        password: action.password
      })
      .pipe(
        map((response) => authActions.signInSuccess({user: response.accountInfo, token: response.token})),
        catchError((error: HttpErrorResponse) => {
          if (error.status === 504) {
            return throwError(() => error);
          }
          return of(authActions.signInFail({error: error.message}))
        }),
        retryWhen((errors) => errors.pipe(delay(4000), take(4)))
      )
    )
  ));

but on RxJs documentation (https://rxjs.dev/api/operators/retryWhen) the retryWhen operator is tagged as deprecated... So, how can i modify this code to do the same things but without deprecated operators? What is the replacement for replyWhen (if there's one)?

  • 1
    Why not use [`retry`](https://rxjs.dev/api/operators/retry) with delay, just like they mention in [the deprecation notes](https://rxjs.dev/api/operators/retryWhen#deprecation-notes)? – Octavian Mărculescu Jul 14 '22 at 10:19

1 Answers1

2

The Deprecation Notes (https://rxjs.dev/api/operators/retryWhen) state to use retry with a delay option. retry takes a RetryConfig object, which has following properties: count, delay and resetOnsuccess.

With your code given above you should try this:

retry({ count: 4, delay: 4000 })
MoxxiManagarm
  • 8,735
  • 3
  • 14
  • 43
  • I wasn't using it because I was putting it in the wrong place. I was mistakenly putting it before map and it not work as intended but just replacing retryWhen with retry works fine. Thank you very much for helping! – Enrico Arnaudo Jul 14 '22 at 10:56
  • By placing put before each operator, it is called regardless of the error and not only for 504 error – Enrico Arnaudo Jul 14 '22 at 10:58