In retrywhen, i able to re-execute http request upon failure just like example at RxJs Observables: run retryWhen after some more async requests. I would like ajax(..) to re-input new option once it fails. Let say I would like to change header or url after first time http request fail. Any example?
Asked
Active
Viewed 398 times
1 Answers
3
All what retryWhen
does is that it re-subscribes to its source Observable. What this means is up to you.
For example you can use Observable.defer()
to return a different Observable on every re-subscription:
let retries = 0;
Observable.defer(() => {
if (retries++ === 3) {
return Observable.of('whatever');
}
return this.http.get(...);
})
.retryWhen((errors: Observable) => errors)
.subscribe(...);
Similarly you could use for example Observable.create()
.

martin
- 93,354
- 25
- 191
- 226