【发布时间】:2018-11-17 15:42:13
【问题描述】:
我对这个概念有很多困难。我有 2 种表格,可以通过同一个 xhr 调用来处理。所以我通过公共流发送表单提交并切换到 xhr 调用。我正在尝试使用 catchError 来处理任何 500,这确实有效(.publish(error) 调用会弹出一个带有错误消息的对话框),但随后订阅会立即完成!我认为这会不断地从 search$ 流中获取输入,直到我调用 this.search$.complete()(这发生在 componentDestroy 上)。关于 RXJS 的“捕捉并继续收听”,我错过了什么?
this.search$.pipe(
tap(() => this.pending = true),
switchMap(criteria => this._dealer.search(criteria)),
catchError(ErrorNotifierService.catchResponseErrorAsObservable)
).subscribe(response => {
this.pending = false;
if (ErrorNotifierService.isCaughtError(response)) {
this._error.publish(ErrorNotifierService.getErrorNotification(response.error));
} else {
this.dsSearchResults.data = response;
}
}, () => console.log('subscribe errored'), () => console.log('subscribe completed?'));
【问题讨论】: