1
0
Fork 0

EventMediator: Log error stack under context

master
Mike Gerwitz 2019-12-09 14:50:22 -05:00 committed by Austin Schaffer
parent e885026e0a
commit 84c2601f1c
2 changed files with 16 additions and 8 deletions

View File

@ -71,7 +71,7 @@ export class EventMediator
private _handleError( e: any ): void
{
let msg: string = '';
let context = {};
let context: Record<string, any> = {};
if ( e instanceof( Error ) )
{
@ -81,6 +81,8 @@ export class EventMediator
{
context = e.context;
}
context.stack = e.stack;
}
this._log.error( msg, context );

View File

@ -96,27 +96,33 @@ describe( 'system.EventLogger captures and logs events', () =>
expect( method_called ).to.be.true;
} );
it( 'context is retrieved from error', () =>
it( 'context and stack are retrieved from error', () =>
{
let method_called = false;
const event_id = 'error';
const err_msg = 'Foo';
const stub_err = new Error( err_msg );
const emitter = new EventEmitter();
const log = createMockLogger();
const err_context = { bar: 'baz' };
const expected_context = {
bar: err_context.bar,
stack: stub_err.stack,
};
log.error = ( str: string, context: any ) =>
{
method_called = true;
expect( str ).to.equal( err_msg );
expect( context ).to.equal( err_context );
expect( context ).to.deep.equal( expected_context );
method_called = true;
};
new Sut( log, emitter );
emitter.emit( event_id, context( new Error( err_msg ), err_context ) );
emitter.emit( event_id, context( stub_err, err_context ) );
expect( method_called ).to.be.true;
} );