I have a query in an Angular service, sometimes I receive an empty array and I want to force the query to be done again in this case
let request = this.http.post(this.searchlUrl, payload).pipe(
retryWhen(errors => errors.pipe(delay(1000), take(2), concat(throwError("Error Data")))),
map( res => {
// If receive res['hotels'] == [] I want to force error
return res;
})
).subscribe(res => {
// Do Something when everything is ok
}, err => {
// Do Something on error
});
});
I am working with retryWhen to make a new request if there is an error (I wait 1 second). My approach is to force an error when receiving empty so that the RetryWhen is activated but I don't know how to do it, and I don't know what is the best practice to force a reconsultation when receiving empty.