Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/system/EventMediator.ts6
-rw-r--r--test/system/EventMediatorTest.ts18
2 files changed, 16 insertions, 8 deletions
diff --git a/src/system/EventMediator.ts b/src/system/EventMediator.ts
index 31b245e..cd5b703 100644
--- a/src/system/EventMediator.ts
+++ b/src/system/EventMediator.ts
@@ -70,8 +70,8 @@ export class EventMediator
private _handleError( e: any ): void
{
- let msg: string = '';
- let context = {};
+ let msg: string = '';
+ 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 );
diff --git a/test/system/EventMediatorTest.ts b/test/system/EventMediatorTest.ts
index 581437c..caab191 100644
--- a/test/system/EventMediatorTest.ts
+++ b/test/system/EventMediatorTest.ts
@@ -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;
} );
@@ -136,4 +142,4 @@ function createMockLogger(): PsrLogger
emergency( _msg: string | object, _context: object ){},
log( _level: any, _msg: string | object, _context: object ){},
};
-} \ No newline at end of file
+}