In my Angular service, I sometimes encounter an issue where I receive an empty array. In such cases, I would like to trigger a fresh query.
let request = this.http.post(this.searchlUrl, payload).pipe(
retryWhen(errors => errors.pipe(delay(1000), take(2), concat(throwError("Error Data")))),
map( res => {
// If the response contains an empty 'hotels' array, I want to force an error
return res;
})
).subscribe(res => {
// Perform actions when everything is ok
}, err => {
// Handle errors here
});
I am utilizing retryWhen to initiate a new request in case of errors (with a 1-second delay). My current approach involves triggering an error upon receiving an empty result to activate the retry mechanism. However, I need guidance on how to achieve this and determine the best practice for forcing a re-query when encountering an empty response.