I wrote my Observable (from an HTTP request) to try again. However, I would not repeat if the server responded with a 429 Too many requests error.
The current implementation is repeated twice, for 1 second, no matter what.
return this.http.get(url,options) .retryWhen(errors => { return errors.delay(1000).take(2); }) .catch((res)=>this.handleError(res));
errors is observable. How can I get the base Response object that caused the error? With it, I can access the server status code and only try again if it is 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 the status code inside retryWhen ?
Live demo on Plunker
Angular 2 rc.6 , RxJS 5 Beta 11 , Typescript 2.0.2
angular typescript observable rxjs5
Beetle juice
source share