【发布时间】:2019-03-30 14:07:36
【问题描述】:
我有一个可能引发错误的服务调用的实现,如果它出错,是否可以重新运行服务调用?
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
}
如果服务调用到达错误回调,有没有办法再次运行服务调用?
【问题讨论】:
-
@sanfalero 我明白了,这个
retry()方法应该在我发出 http 请求的同一个函数中调用? -
你可以在任何 observable 上使用它。也许像 this.captureService.CaptureScreenService(captureModel).pipe(retry(3)).subscribe(...
-
@sanfalero 就像一个魅力!谢谢;如果您想将此作为答案,我会将其选为已接受
标签: angular typescript xmlhttprequest rxjs observable