I am struggling a bit with how to execute code after an error happened in HttpClient. I would like to know how to set the flag that would turn off a loading spinner when the http called failed. I am using RxJs 5.5.2 and 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)
}
So in the happy path isLoading = false works but not sure how to do that after catch. It is not working the way the code is now. I am also using a custom error handler as per Angular docs
public handleError<T>(operation = 'operation', error: any, result?: T) {
// do logging etc
return Observable.of(result as T); // return empty result
}
HttpInterceptor..catch<any, LegalTerm>(this._trace.handleError)is code that will bite you sooner or later. Fix it.