Answer the question
In order to leave comments, you need to log in
How to prevent Observable from stopping?
There is such a code, in case of an error, the interval stops, and the observable becomes executed, how to prevent this?
Observable.interval(3000)
.do(value => console.log('attempt #', value))
.switchMap(() => this.http.get(url))
.catch (err => Observable.empty())
.subscribe(data => console.log(data));
Answer the question
In order to leave comments, you need to log in
You need to create a new Observable inside switchMap that will catch the error:
Observable.interval(3000)
.do(value => console.log('attempt #', value))
.switchMap(() => Observable.defer(() => this.http.get(url))
.map(data => data)
.catch(err => console.log(err))
)
.catch (err => Observable.empty())
.subscribe(data => console.log(data));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question