I have a service which run a timer in its constructor. The timer calls an asynchrony function which call an API and should return an Observable. It is running fine when everything is OK. I'm trying to implement error handling now, whenevr the API is down. The problem is that whenever an error occurred, the timer executions stops.
See my code:
subscription : Subscription;
constructor(private httpClient : HttpClient)
{
this.subscription = timer(0, 10000).pipe
(
switchMap(() => this.getData();
}).subscribe();
}
getData(): Observable<someModel>
{
return this.httpClient.get<someModel>(<url>)
.pipe(
tap(response =>
{
do something
}),
catchError(error =>
{
<doSomeErrorHandling>
return throwError(error);
})
);
}