Skip to content

Commit

Permalink
Merge pull request #3161 from jayphelps/errors
Browse files Browse the repository at this point in the history
fix(Observable): Another attempt at fixing error rethrows in v5
  • Loading branch information
benlesh authored Dec 15, 2017
2 parents 1e20a8d + 541b49d commit c2b2251
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
14 changes: 14 additions & 0 deletions spec/Observable-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,20 @@ describe('Observable', () => {
}).to.throw();
});

it('should rethrow if sink has syncErrorThrowable = false', () => {
const observable = new Observable(observer => {
observer.next(1);
});

const sink = Subscriber.create(() => {
throw 'error!';
});

expect(() => {
observable.subscribe(sink);
}).to.throw('error!');
});

describe('forEach', () => {
it('should iterate and return a Promise', (done: MochaDone) => {
const expected = [1, 2, 3];
Expand Down
2 changes: 1 addition & 1 deletion src/Observable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export class Observable<T> implements Subscribable<T> {
if (operator) {
operator.call(sink, this.source);
} else {
sink.add(this.source ? this._subscribe(sink) : this._trySubscribe(sink));
sink.add(this.source || !sink.syncErrorThrowable ? this._subscribe(sink) : this._trySubscribe(sink));
}

if (sink.syncErrorThrowable) {
Expand Down
1 change: 1 addition & 0 deletions src/Subscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export class Subscriber<T> extends Subscription implements Observer<T> {
}
if (typeof destinationOrNext === 'object') {
if (destinationOrNext instanceof Subscriber) {
this.syncErrorThrowable = destinationOrNext.syncErrorThrowable;
this.destination = (<Subscriber<any>> destinationOrNext);
(<any> this.destination).add(this);
} else {
Expand Down

0 comments on commit c2b2251

Please sign in to comment.