el_pup_le
el_pup_le

Reputation: 12189

How to throw and catch a BehaviorSubject Observable error

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

Answers (1)

Max Koretskyi
Max Koretskyi

Reputation: 105547

You can simply call error on the subject:

this.bs.error(err);

Upvotes: 1

Related Questions