我有一系列可观察的事物。这是一段代码:
//get dynamic tree
flatMap(res => this.dynamicReportId !== null ? this.reportService.getDynamicTree(this.dynamicReportId) : of({})),
tap(res => this.dynamicTree = res),
//get dynamic report
flatMap((res) => this.dynamicReportId !== null ? this.reportService.getDynamicReport(this.dynamicReportId) : of({})),
但是,当我从第一个请求(获取动态树)收到500个API错误时,链停止并且从不进入第二个flatMap(动态报告)。
这里是功能this.reportService.getDynamicTree()
:
get(path: string, params: HttpParams = new HttpParams()): Observable<any> {
return this.http.get(`${environment.apiBaseUrl}${path}`, {headers: this.setHeaders(true), params: params}).pipe(
catchError(error => this.processError(path, error)),
map((res: Response) => res));
}
this.processError
返回observableThrowError(res);
的位置>
如果发生错误,我应该返回什么以继续进行连锁?还是其他原因?
我有一系列可观察的事物。这是一段代码://获取动态树flatMap(res => this.dynamicReportId!== null?this.reportService.getDynamicTree(this.dynamicReportId)...
首先-延续链条式样打败了链条的整个概念。但是,我认为可以通过使用一些相当简单的链式迭代器并处理HttpClient和服务引发的错误来解决此问题。