I've seen a dozen ways to implement retry strategies, and I feel like I'm really close. What I have here doesn't throw an error after takeWhile() completes.
getItems(): Observable<ListItem[]> {
return this.authHttp.get(URL + '/items')
.retryWhen(e =>
e.scan((errorCount, err) => errorCount + 1, 0)
.takeWhile(errorCount => errorCount < 4)
.delay(3000))
.map(this.dataService.extractData)
.catch(err => this.dataService.handleError(err, 'The items could not be retrieved.'))
}
I've seen some jagged looking code snippets that might get it done. I experimented with inserting a .finally() before the .delay().
Once I get this one solved, I'll want to pass the errorCount back up to my subscription so that I can display something useful. "Retry 1 of 4." Something to let the user know what is going on.