I'm trying to pass any errors that might occur in an HTTP request to a common 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, this is lost. I've tried defining this as a fat arrow, but i get type errors from the TS compiler. I've used the exact syntax in the Observable documentation.