Im using rxJS in Angular and have a set of Behavior Subjects that are exposed as a readonly Observable
public _data = new BehaviorSubject<DataItem[]>([]);
public readonly data$ = this._data.asObservable();
now I have noticed that if I subscribe directly to the BehaviorSubject
and there is an error it will throw the error to the console.
but if I subscribe to the Observable with same error I don't get any messages and the listener is then unsubscribed automatically.
I know this is the expected behavior but...
I would like to know what is the pattern to avoid code duplication on errors e.g.
this.myDataService.data$.subscribe(d=> throwSomeError(), e=> handleError(e));
//or use this:
this.myDataService.data$.subscribe(d=> throwSomeError()).catch(e=> handleError(e));
the handleError(e)