I'm trying to implement an api call that will be
- retried few times if there is any errors
- after a specific time delay
- with some other condition check like - if returned success response json has any field null, I'll retry the api call
I tried to implement what is mentioned here - Rxjs Retry with Delay function
Following is my code segment
Api call
delay = 5000;
retryCount = 5;
return this.httpClient.post(http://localhost:8080/info,JSON.stringify(data))
.pipe(
retryWhen(errors =>
errors.pipe(
delay(this.delay),
take(this.retryCount),
tap(val => {
console.log('Retrying.');
}),
concatMap(() => Observable.throw(new Error('Retry limit exceeded!')))
)
)
);
Processing the response
this.searchService.searchInfo(param1, param2).subscribe(data => { this.handleSuccessResponse(data) }, (error) => {
if (error) {
// Handle specific error here
handleErrorResponse(error);
}
});
handleSuccessResponse(data){
// handle success response here
}
handleErrorResponse(error){
// Handle generic error here
}
The issue I am getting, before retrying for 5 times as I mentioned in the code, the exception in the concatMap is getting throwed. What I am missing here?
I'm using RxJS 6.4 with Angular12