retryWhen with backoff

拟墨画扇 提交于 2019-12-24 06:44:49

问题


Trying to retry (with backoff logic) when error on http.get

return this.http.get(this.urlToBackend)
            .map((res: Response) => res.json())
            .retryWhen(errors =>
                errors
                    .zip(Observable.range(3, 15), (_, i) => i)
                    .flatMap(i => {
                        if (i >= 15) {
                            throw errors;
                        }
                        let t = (Math.pow(2, i)) * 1000;
                        return Observable.timer(t);
                    }))
            .catch((error: any) => this.handleError(error, false, 0, this.urlToBackend));

Keep getting this error:

TypeError: this.http.get(...).map(...).retryWhen is not a function
    at IOService.getUserDetails (http://localhost:4200/main.bundle.js:303:14)
    at NavirComponent.ngOnInit (http://localhost:4200/main.bundle.js:3328:24)
    at Wrapper_NavirComponent.ngDoCheck (/AppModule/NavirComponent/wrapper.ngfactory.js:22:53)
    at CompiledTemplate.proxyViewClass.View_AppWrapperComponent0.detectChangesInternal (/AppModule/AppWrapperComponent/component.ngfactory.js:100:28)
    at CompiledTemplate.proxyViewClass.AppView.detectChanges (http://localhost:4200/vendor.bundle.js:81933:14)
    at CompiledTemplate.proxyViewClass.DebugAppView.detectChanges (http://localhost:4200/vendor.bundle.js:82128:44)
    at CompiledTemplate.proxyViewClass.AppView.internalDetectChanges (http://localhost:4200/vendor.bundle.js:81918:18)
    at CompiledTemplate.proxyViewClass.View_AppWrapperComponent_Host0.detectChangesInternal (/AppModule/AppWrapperComponent/host.ngfactory.js:29:19)
    at CompiledTemplate.proxyViewClass.AppView.detectChanges (http://localhost:4200/vendor.bundle.js:81933:14)
    at CompiledTemplate.proxyViewClass.DebugAppView.detectChanges (http://localhost:4200/vendor.bundle.js:82128:44)
    at ViewRef_.detectChanges (http://localhost:4200/vendor.bundle.js:60587:20)
    at http://localhost:4200/vendor.bundle.js:41131:67
    at Array.forEach (native)
    at ApplicationRef_.tick (http://localhost:4200/vendor.bundle.js:41131:25)
    at ApplicationRef_._loadComponent (http://localhost:4200/vendor.bundle.js:41106:14)

回答1:


Try to add import

import "rxjs/add/operator/mergeMap";


来源:https://stackoverflow.com/questions/41818111/retrywhen-with-backoff

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!