I'm trying to throw an error inside a rxjs Observable
new Observable(subscriber => {
Observable.throw("error1");
return Observable.throw("error2");
})
.subscribe(
() => {},
err => console.error(err)
);
error 1 is not caught.
error2 gives a compilation error:
Argument of type '(this: Observable<{}>, subscriber: Subscriber<{}>) => ErrorObservable<string>' is not assignable to parameter of type '(this: Observable<{}>, subscriber: Subscriber<{}>) => TeardownLogic'. Type 'ErrorObservable<string>' is not assignable to type 'TeardownLogic'
what is the proper way to throw an error inside an observable?
Observable.throw(new Error("error1"))
. – Lenee