-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Description
RxJS version:
5.5
Code to reproduce:
const subject = new Subject<number>();
it('will not receive error', () => {
const s1 = subject.subscribe(() => {}); // No error handler
const errorSpy = jasmine.createSpy('subscription error spy')
const s2 = subject.subscribe(() => {}, errorSpy);
expect(() => {
subject.error(1);
}).toThrow(1);
expect(errorSpy).toHaveBeenCalled(); // Will fail
});
it('will receive error', () => {
const s1 = subject.subscribe(() => {}, () => {}); // With error handler
const errorSpy = jasmine.createSpy('subscription error spy')
const s2 = subject.subscribe(() => {}, errorSpy);
expect(() => {
subject.error(1);
}).not.toThrow(1);
expect(errorSpy).toHaveBeenCalled(); // Will pass
});
Expected behavior:
All subscriptions should receive error events.
Actual behavior:
A race condition is created where only the first subscribers receive an error event. Once one subscribe doesn't override the default error handler an error is thrown and code execution is halted.
Additional information:
This is been an issue for us when dealing with XML requests. Some of our code relies on receiving an error event. In our codebase we now have to be very careful and can't rely on publicly exposed observables to receive errors.
Metadata
Metadata
Assignees
Labels
No labels