Reputation: 12189
I have an observable
bs = new BehaviorSubject<BS>(new BS());
onObsChange(): Observable<BS> {
return this.bs.asObservable();
}
then I subscribe to the observable
this.sessionService.onBSChange().subscribe(
data => self.user = data.user,
error => console.log(error)
);
I can get data in the subscription callback but don't know how to catch or throw errors with observables/behavior subjects.
this.bs.next(newValue); // data => ...
How can I throw an error with observable bs that will be caught in the onBSChange() subscription?
Upvotes: 0
Views: 2309
Reputation: 105547
You can simply call error
on the subject:
this.bs.error(err);
Upvotes: 1