我有并行 API 呼叫。如果第二個失敗,如何繼續從其中一個獲取資料?
forkJoin([a,b])
.subscribe({
next: ((data) => {
const [first, second] = data;
})
uj5u.com熱心網友回復:
在我看來, combineLatest 是您正在尋找的東西,每個可觀察物件都有一個 catchError 來管理錯誤。就像是:
combineLatest([
obs1$.pipe(catchError(() => of(null)),
obs2$.pipe(catchError(() => of(null)),
]).subscribe(([first, second]) => { console.log(first,second); });
uj5u.com熱心網友回復:
我已經找到了解決方案,我們需要處理每個 observable 中的錯誤并回傳 of()。
catchError(() => of([]))
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/529098.html
