【发布时间】:2018-11-18 19:54:20
【问题描述】:
我的Subject 正在返回错误,但订阅Subject 的Observable 的错误方法正在执行,即使订阅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 的错误方法正在执行,即使 switchMap 返回 ok,这是因为“外部”Subject 正在抛出错误。
有什么方法可以防止订阅者也收到错误消息?这并不重要,因为我可以过滤返回的error 以确定是否需要在这里处理;但它有点臭,我希望这个错误块根本不执行。
【问题讨论】:
-
你能提供stackbiz吗,真的没有从中得到什么
标签: typescript rxjs reactive-programming