I've composed my Observable (from an HTTP request) to retry on failure. However, I would like to not retry if the server responded with 429 Too many requests
error.
The current implementation retries twice, 1 second apart, no matter what.
return this.http.get(url,options)
.retryWhen(errors => {
return errors.delay(1000).take(2);
})
.catch((res)=>this.handleError(res));
errors
is an Observable. How can I get the underlying Response
object that caused the error? With it I can access the server's status code and only retry if it's not 429:
return this.http.get(url,options)
.retryWhen(errors => {
if($code == 429) throw errors;
else return errors.delay(1000).take(2);
})
.catch((res)=>this.handleError(res));
How can I get status code within retryWhen
?
Live demo on Plunker
Angular 2 rc.6
, RxJS 5 Beta 11
, Typescript 2.0.2