Reputation: 4233
I have the following sample:
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))
I want to have a retryWhen which will retry only his immediate parent. And then in case of a global error I will retry the whole sequence. Is there an easy way with RxJS 5 ?
UPD: These are just examples. In reality situation is more complex I just need an idea for this.
Upvotes: 1
Views: 2180
Reputation: 18663
You just need put the retryWhen
inside the switchMap
:
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))
Upvotes: 2