I know we can retry a failed HTTP API request through retry
or retryWhen
pipe mehtods from rxjs. I want to do something similar on a successful API call, based on a particular condition in the response received.
Any help on this is much appreciated.
CodePudding user response:
It would be better to use the repeat
operator from RxJs for the successful request because the repeat
operator resubscribes when it receives onComplete()
but not by error. Whereas, retry
operator resubscribes when it receives onError()
Please see this Stackblitz example where a successful request is repeated twice. You can open the console and see the response repeated multiple times.
CodePudding user response:
Maybe you can use the completed stage of the observable, so after subscription, you will have: next, error and completed. If that condition is coming from the api, like this you will have access to the value and inside the complete code block you can do the repetition.