I am using Angular 2 HTTP library which returns an observable. I want to implement retry on certain error status/code.
I have an issue, if the error is not 429, Observable.of(error)
is getting executed in error case to retry, but when all your 2 retry fails the execution of flow goes to success block instead of catch block.
How to make execution of flow to catch block in all retry fails?
return this.http.get(url,options)
.retryWhen((errors) => {
return errors
.mergeMap((error) => (error.status === 429) ? Observable.throw(error) : Observable.of(error))
.take(2);
})
.toPromise()
.then((res:Response) => console.log('In Success Block'))
.catch((res) => this.handleError(res));
will it resolve my problem
return this.http
.post(url, JSON.stringify(body), requestOptions).retryWhen((errors) => {
return errors
.mergeMap((error) => (error.status === 404) ? Observable.throw(error) : Observable.of(error))
.take(2);
}).map((res:Response) =>{
if (res.status === 200)
return res;
else
return Observable.throw(res);
})
.toPromise();