I am trying to pass on any errors that may occur in the HTTP request to the general logging service from all my services:
import { Observable } from 'rxjs/Observable'; import 'rxjs/add/operator/catch'; constructor(logger: LoggerService) { } doSomething(): Observable<any> { return this.http .post('/foo/bar', {}) .catch(this.notifyErrors); } protected notifyErrors(error: any): Observable<any> { this.logger.log(error); return Observable.throw(error); }
Unfortunately, inside the notifyErrors method, notifyErrors is lost. I tried to define this as a bold arrow, but I get type errors from the TS compiler. I used the exact syntax in the Observable documentation.
source share