0
I need to retain my http request after 5 seconds in case of error.
I tried to implement with retryWhen
but I get:
Property 'retryWhen' does not exist on type 'Observable'. [2339]
I tried so:
listaDepartamentos(){
this.myservice.consultaDepartamentos()
.pipe(
take(1)
)
.retryWhen(error => {
return error
.flatMap((error: any) => {
if(error.status === 503) {
return Observable.of(error.status).delay(5000)
}
return Observable.throw({error: 'No retry'});
})
.take(5)
.concat(Observable.throw({error: 'Sorry, there was an error (after 5 retries)'}));
});
.subscribe((res) => {
console.log(res)
},
(err) => {
console.log(err)
})
}
At my service:
consultaDepartamentos():Observable<any>{
return this._http.get<any>(AppSettings.API_ENDPOINT + 'global/departamento/listar',
{observe: 'response'})
}
You are importing the operator?
– renanvm
yes, he finds the operator
– veroneseComS
take a look at this example, maybe you can help https://stackblitz.com/edit/angular-cwnknr?file=app%2Fapp.component.ts
– renanvm
I’ll try. you could add an answer explaining the code?
– veroneseComS