In the event that my API does not return data within 5 seconds, I need to call a different one. Attempted implementation:
this.service.returnData1(param1, param2)
.pipe(timeout(5000), finalize(() => this.callSecondApi()))
.subscribe(
data => {
this.myList = data.filter(item => !this.removeStuffFromList(item, data));
if (this.myList.length > 0) {
//perform additional tasks
this.originalList = this.myList;
}
},
(err) => {
console.log(err.message);
}
)
callSecondApi(){
this.service.returnData2(param1, param2).subscribe(
data1 => {
this.myList = data1.filter(item => !this.removeStuffFromList(item, data1));
}
if (this.myList.length > 0) {
this.originalList = this.myList;
}
},
(err) => console.log(err.message)
)
}
What is the most effective approach for resolving this issue? Tried various solutions involving switchMap, tap, mergeMap, but none worked due to the necessity of adding a timeout to the first subscribe operation. Thank you!