如果一个HTTP调用在Angular 2中失败,并且一个HTTP调用依赖于另一个HTTP调用,请重试所有HTTP调用

如果一个HTTP调用在Angular 2中失败,并且一个HTTP调用依赖于另一个HTTP调用,请重试所有HTTP调用,angular,rxjs,observable,angular2-http,Angular,Rxjs,Observable,Angular2 Http,使用这个Angular 2代码,对“./customer.json”进行http调用,然后使用其中返回的url进行进一步调用。如果第二个调用失败,如何使用rxjs重试方法使其重试这两个调用?目前,它似乎只是重试第二次 this.http.get('./customer.json') .map((res: Response) => { this.customer = res.json(); return this.customer; }) .flatMap((customer

使用这个Angular 2代码,对“./customer.json”进行http调用,然后使用其中返回的url进行进一步调用。如果第二个调用失败,如何使用rxjs重试方法使其重试这两个调用?目前,它似乎只是重试第二次

this.http.get('./customer.json')
.map((res: Response) => {
    this.customer = res.json();
    return this.customer;
})
.flatMap((customer) => {
    return this.http.get(customer.contractUrl)).map((res: Response) => res.json()
})
.retry(1);

因此,如果
this.http.get(customer.contractUrl))
失败,我如何让它再次重试
http.get('./customer.json')
this.http.get(customer.contractUrl))

我不确定为什么我的原始代码似乎不起作用,但我尝试使用catch方法,它似乎起了作用

makeCall(isRetry = false){
    return this.http.get('./customer.json')
        .map((res: Response) => {
            this.customer = res.json();
            return this.customer;
        })
        .flatMap((customer) => {
            return this.http.get(customer.contractUrl)).map((res: Response) => res.json()
        })
        .catch((err) => {
            if (isRetry === false){
                return this.makeCall(true);
            }

            return Observable.throw(err);
        });
}

我会制作一些JSBIN,看看我是否能弄明白这应该是可行的……你确定这里没有缓存吗?或者您可以提供jsbin来复制您的问题吗?在
map
中指定一个值不是一个好做法。尝试使用
do
运算符进行分配
this.http.get('./customer.json')。重试(1)。映射…