Skip to content

Instantly share code, notes, and snippets.

@mactyr
Last active July 6, 2018 23:35
Show Gist options
  • Save mactyr/1ae4fdb0f94cff265f815d9b42c2c5fd to your computer and use it in GitHub Desktop.
Save mactyr/1ae4fdb0f94cff265f815d9b42c2c5fd to your computer and use it in GitHub Desktop.
http retryWhen that throws last error when retries are exhausted
let retries = 0;
this.http
.get(this.url)
.retryWhen(error => {
return error
.flatMap((error: any) => {
retries++;
if (retries <= 5 && error.status === 503) {
return Observable.of(error.status).delay(1000)
}
return Observable.throw(error);
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment