I am using RxJS version “5.0.0-beta.12”
var innerObservable = new Observable(observer => {
console.log('Inner observable call failed');
observer.error(new Error('Call failed!'));
})
var outerObservable = new Observable(observer => {
innerObservable.subscribe(
data => {
observer.next(data);
observer.onCompleted();
},
err => {
//observer.throw(err); // `console.error` doesn't get called
observer.error(err); // // `console.error` it's called
}
)
});
outerObservable.subscribe(
next => {
console.log('ok!');
}
, err => {
console.error('error');
}
, () = > {
console.log('done');
}
);
Subscriber class. It has an error() method, but no throw() method.
There is Observable.throw(), but that's a different thing.
> observer. throw(error) does not exist.> Observable.throw(err) is an observable that only sends out an error notification.> observer.error() is usually used in Observable.create() callbacks to send errors to newly subscribed observers Notification (like .next() or .complete).
What is the difference between observer.throw (error) and observer.error (error)?
I am using RxJS version "5.0.0-beta.12"
var innerObservable = new Observable(observer => {
console.log('Inner observable call failed');
observer.error(new Error('Call failed!'));
})
var outerObservable = new Observable(observer => {
innerObservable.subscribe(
data => {
observer.next(data);
observer.onCompleted();
},
err => {
//observer.throw(err); // `console.error` doesn't get called
observer.error(err); // // `console.error` it's called
}
)
});
outerObservable.subscribe(
next => {
console.log('ok!');
}
, err => {
console.error('error');
}
, () = > {
console.log('done');
}
);
Actually your observer It is an instance of Subscriber class
. It has an error() method, but no throw() method.
There is Observable.thr ow(), but that is a different thing.
> observer.throw(error) does not exist.> Observable.throw(err) is an observable that only sends out an error notification.> observer .error() is usually used in the Observable.create() callback to send error notifications to newly subscribed observers (just like .next() or .complete).
p>