2017-03-29 6 views
0

私は、次のサンプルを持っている:内部観測可能なエラーだけを再試行する方法は?

const result = http.get('http://google.com') 

       .switchMap(() => 'http://example.com') 

       // This retry should retry only example.com 
       .retryWhen(error => 
        (error instanceof Response && error.status == 429) ? 
        Observable.timeout(5000) : Observable.throw(error)) 

       // This retry should retry google.com 
       .retryWhen(error => Observable.timeout(5000)) 

は、私は彼の直接の親を再試行しますretryWhenを持っていると思います。そして、全体的なエラーの場合、私は全体のシーケンスを再試行します。 RxJS 5の簡単な方法はありますか?

UPD:これは単なる例です。実際には、状況はより複雑です。私はちょうどこれのためのアイデアが必要です。

答えて

1

あなただけswitchMapretryWhenを置く必要があります。

const inner = http.get('http://example.com') 
     // This retry should retry only example.com 
     .retryWhen(error => 
     (error instanceof Response && error.status == 429) ? 
     Observable.timer(5000) : Observable.throw(error)) 

const outer = http.get('http://google.com') 
    .switchMap(() => inner) 
    // This retry should retry google.com 
    .retryWhen(error => Observable.timeout(5000)) 
関連する問題