Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(forkJoin): catch and forward selector errors #3261

Merged
merged 2 commits into from
Jan 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions spec/observables/forkJoin-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,20 @@ describe('Observable.forkJoin', () => {
expectObservable(e1).toBe(expected);
});

it('should raise error when the selector throws', () => {
function selector(x, y) {
throw 'error';
}

const e1 = Observable.forkJoin(
hot('--a-|'),
hot('---b-|'),
selector);
const expected = '-----#';

expectObservable(e1).toBe(expected);
});

it('should allow unsubscribing early and explicitly', () => {
const e1 = hot('--a--^--b--c---d-| ');
const e1subs = '^ ! ';
Expand Down
8 changes: 7 additions & 1 deletion src/internal/observable/ForkJoinObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,13 @@ class ForkJoinSubscriber<T> extends OuterSubscriber<T, T> {
}

if (haveValues === len) {
const value = resultSelector ? resultSelector.apply(this, values) : values;
let value: any;
try {
value = resultSelector ? resultSelector.apply(this, values) : values;
} catch (err) {
destination.error(err);
return;
}
destination.next(value);
}

Expand Down