在 HttpClient 中发生错误后,我正在努力解决如何执行代码。我想知道如何设置在 http 调用失败时关闭加载微调器的标志。我正在使用 RxJs 5.5.2 和 Angular 5
private fetch(): Observable<LegalTerm[]> {
this.isLoading = true;
return this._http
.get<LegalTerm[]>(AppSettings.LegalTermUrl, { withCredentials: true })
.do(() => this.isLoading = false)
.catch<any, LegalTerm>(this._trace.handleError)
.do(() => this.isLoading = false)
}
所以在快乐的道路上isLoading = false
工作,但不知道之后该怎么做catch
。它不像现在的代码那样工作。我还根据 Angular 文档使用自定义错误处理程序
public handleError<T>(operation = 'operation', error: any, result?: T) {
// do logging etc
return Observable.of(result as T); // return empty result
}