Im uses rxJS in Angular and has a set of behavior objects that display as readonly Observable
public _data = new BehaviorSubject<DataItem[]>([]);
public readonly data$ = this._data.asObservable();
Now I noticed that if I subscribe directly to BehaviorSubject, and an error occurs, it will output the error to the console.
but if I subscribe to Observable with the same error, I do not receive any messages and the listener is automatically canceled.
I know this is the expected behavior, but ...
I would like to know what a template is to avoid duplication of code in case of errors, for example.
this.myDataService.data$.subscribe(d=> throwSomeError(), e=> handleError(e));
this.myDataService.data$.subscribe(d=> throwSomeError()).catch(e=> handleError(e));
handleError (e)
source
share