IvanS95
IvanS95

Reputation: 5742

Angular 6+ / Retry Service Call on Error Callback?

I have an implementation of a service call which might throw an error, is it possible to rerun the service call if it errors out?

captureMultiScreen(elem: Alert, overwrite: boolean, success?: Function, failed?: Function) {
this.spinnerValue = true;
const captureModel: Capture = {
  member_id: elem.member_id,
  gateway: elem.gateway,
  account: elem.account,
  alert_id: elem.alert_id,
  transaction_id: elem.transaction_id,
  overwrite: overwrite
};

this.captureService.CaptureScreenService(captureModel).subscribe(result => {
  this.capServiceResponse = result;
},
(error) => {
  // Retry "CaptureScreenService" here
}

Is there a way to just run the service call again if it reached the error callback?

Upvotes: 0

Views: 1114

Answers (1)

sanfalero
sanfalero

Reputation: 382

You can use the retry function. In your code it would be something like:

this.captureService.CaptureScreenService(captureModel)
  .pipe(retry(3)).subscribe(...)

Upvotes: 5

Related Questions