RxJS "throws new error" against "Observable.throw"
1 answer
Observable.throw
returns error on streams. For example, I'm expecting Observable
, but for some reason I want to return an error. In these cases, cannot be used throw new Error()
.
For example:
var source = someStream$
.flatMap(data => data?
Rx.Observable.of(data): // Or any other async operation
Rx.Observable.throw('invalid data'));
There flatMap
is a stream waiting for the Observable, if we need to use throw new Error()
, we need to do a hack.
It may have other advantages to work well with rx statements that I am not aware of.
+2
source to share