【发布时间】:2021-12-27 04:39:37
【问题描述】:
https://stackblitz.com/edit/rxjs-catcherror-withmapoperators-lwutxg?file=index.ts
const fakeRequest$ = of().pipe(
tap((_) => console.log('fakeRequest')),
throwError
);
const iWillContinueListening$ = fromEvent(
document.getElementById('continued'),
'click'
).pipe(
switchMap((_) =>
fakeRequest$.pipe(
catchError((_) => {
return throwError('x');
})
)
)
);
const parent = iWillContinueListening$.pipe(
catchError((err) => {
console.log('er', err);
return of('err');
})
);
parent.subscribe(console.log);
如何在 iWillContinueListening$ 出错时激活 catchError on parrent 并仍然发出值?
【问题讨论】:
-
我很难说出你想做什么。当链发出
error通知时,它将终止并且永远不会再有next排放。也许您正在寻找retry()或者甚至是onErrorResumeNext()?
标签: error-handling rxjs try-catch rxjs-observables rxjs-pipeable-operators