Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can i replace retryWhen on this ngrx effect?

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)?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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 })
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading