Observables have a retry method which you can use by throwing an error as long as the data is not valid:
let src: Observable<any>;// the source Observable
src.map(data => {
if (!validate(data)) {
throw "Invalid data";
}
return data;
})
.retry() // you can limit the number of retries
.subscribe(data => {
// Do something with the data
});
you can use retryWhen if you need to check the error:
let src: Observable<any>;// the source Observable
src.map(data => {
if (!validate(data)) {
throw "Invalid data";
}
return data;
})
.retryWhen(errors => errors.map(err => {
if (err != "Invalid data") {
throw err;
}
})
.subscribe(data => {
// Do something with the data
});