Skip to content

Commit f94560c

Browse files
cartantbenlesh
authored andcommitted
fix(subscribe): ignore syncError when deprecated (#3749)
* test(catchError): add failing test * fix(subscribe): ignore syncError when deprecated Unless using the deprecated syncError handling, the syncErrorThrowable flag should be ignored.
1 parent 3746c41 commit f94560c

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

spec/operators/catch-spec.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect } from 'chai';
2-
import { of, throwError, EMPTY, from } from 'rxjs';
2+
import { concat, Observable, of, throwError, EMPTY, from } from 'rxjs';
33
import { catchError, map, mergeMap } from 'rxjs/operators';
44
import { TestScheduler } from 'rxjs/testing';
55
import * as sinon from 'sinon';
@@ -285,6 +285,21 @@ describe('catchError operator', () => {
285285
});
286286
});
287287

288+
it('should catch errors throw from within the constructor', () => {
289+
// See https://github.com/ReactiveX/rxjs/issues/3740
290+
const source = concat(
291+
new Observable<string>(o => {
292+
o.next('a');
293+
throw 'kaboom';
294+
}).pipe(
295+
catchError(_ => of('b'))
296+
),
297+
of('c')
298+
);
299+
const expected = '(abc|)';
300+
expectObservable(source).toBe(expected);
301+
});
302+
288303
context('fromPromise', () => {
289304
type SetTimeout = (callback: (...args: any[]) => void, ms: number, ...args: any[]) => NodeJS.Timer;
290305

src/internal/Observable.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,11 @@ export class Observable<T> implements Subscribable<T> {
194194
if (operator) {
195195
operator.call(sink, this.source);
196196
} else {
197-
sink.add(this.source || !sink.syncErrorThrowable ? this._subscribe(sink) : this._trySubscribe(sink));
197+
sink.add(
198+
this.source || (config.useDeprecatedSynchronousErrorHandling && !sink.syncErrorThrowable) ?
199+
this._subscribe(sink) :
200+
this._trySubscribe(sink)
201+
);
198202
}
199203

200204
if (config.useDeprecatedSynchronousErrorHandling) {

0 commit comments

Comments
 (0)