我有一个服务调用的实现,它可能会引发错误,如果出现错误,是否可以重新运行该服务调用?
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
}
如果到达错误回调,是否有办法再次运行服务调用?
答案 0 :(得分:5)
您可以使用retry function。在您的代码中,它将类似于:
this.captureService.CaptureScreenService(captureModel)
.pipe(retry(3)).subscribe(...)