Issue
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)?
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 })
Answered By - MoxxiManagarm
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.