我遇到这样一种情况:我的Subject
返回一个错误,但订阅该Subject
的Observable
的error方法正在执行,即使该Observable
的订阅没有失败并返回错误。如下所示:
this.createPayment$ = this.wizard$.pipe(
switchMap((wizard) => willReturnAnErrorObservable()),
share()
);
this. handleSuccessSubscription = this.createPayment$.pipe(
filter((someEvent: SomeEvent) => event.succeeded),
switchMap((someEvent: SomeEvent) =>
// this is never called because the filter above does not pass
doesNotFailObservable()
)
).subscribe((confirmedPayment: PaymentDeviceEvent) => {
// not important
},
(error) => {
// this error block is still being called, even though the this.
// handleSuccessSubscription switchMap is not executed, because the
// this.handleSuccessSubscription$ above returns an error
});
在这段代码中,正在执行createPaymentSuccessfulSubscription
的error方法,即使switchMap
返回ok,这是因为“外部”Subject
抛出了一个错误。
有没有办法防止订阅者也收到错误?这并不重要,因为我可以对返回的error
进行过滤,以确定是否需要在这里处理它;但是它有点难闻,我希望这个错误块根本不被执行。
https://stackoverflow.com/questions/50765971
复制相似问题