首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >RxJS:主题错误向下渗透到订阅者

RxJS:主题错误向下渗透到订阅者
EN

Stack Overflow用户
提问于 2018-06-09 01:45:32
回答 1查看 247关注 0票数 0

我遇到这样一种情况:我的Subject返回一个错误,但订阅该SubjectObservable的error方法正在执行,即使该Observable的订阅没有失败并返回错误。如下所示:

代码语言:javascript
运行
复制
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进行过滤,以确定是否需要在这里处理它;但是它有点难闻,我希望这个错误块根本不被执行。

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50765971

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档