Skip to content

Commit

Permalink
feat(UnsubscriptionError): add messages from inner errors to output m…
Browse files Browse the repository at this point in the history
…essage

- Adds improved console logging behavior

closes #1590
  • Loading branch information
benlesh committed Apr 9, 2016
1 parent 9784055 commit dd01279
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
28 changes: 28 additions & 0 deletions spec/util/UnsubscriptionError-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {expect} from 'chai';
import * as Rx from '../../dist/cjs/Rx';

const { Observable, UnsubscriptionError } = Rx;

/** @test {UnsubscriptionError} */
describe('UnsubscriptionError', () => {
it('should create a message that is a clear indication of its internal errors', () => {
const err1 = new Error('Swiss cheese tastes amazing but smells like socks');
const err2 = new Error('User too big to fit in tiny European elevator');
const source1 = Observable.create(() => () => { throw err1; });
const source2 = Observable.timer(1000);
const source3 = Observable.create(() => () => { throw err2; });
const source = source1.merge(source2, source3);

const subscription = source.subscribe();

try {
subscription.unsubscribe();
} catch (err) {
expect(err instanceof UnsubscriptionError).to.equal(true);
expect(err.message).to.equal(`2 errors occurred during unsubscription:
1) ${err1}
2) ${err2}`);
expect(err.name).to.equal('UnsubscriptionError');
}
});
});
4 changes: 3 additions & 1 deletion src/util/UnsubscriptionError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
*/
export class UnsubscriptionError extends Error {
constructor(public errors: any[]) {
super('unsubscriptoin error(s)');
super();
this.name = 'UnsubscriptionError';
this.message = errors ? `${errors.length} errors occurred during unsubscription:
${errors.map((err, i) => `${i + 1}) ${err.toString()}`).join('\n')}` : '';
}
}

0 comments on commit dd01279

Please sign in to comment.