Skip to content

Commit

Permalink
leveraged the error formatter when data is an Error (#86)
Browse files Browse the repository at this point in the history
for events that are not handled specifically by eventName, the error formatter is used to provide more useful information when the event data is an Error
  • Loading branch information
travi authored and arb committed Feb 8, 2017
1 parent f0f83c9 commit e32cec6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/index.js
Expand Up @@ -174,6 +174,12 @@ class GoodConsole extends Stream.Transform {
return next(null, internals.utility.formatResponse(data, tags, this._settings));
}

if (data.data instanceof Error) {
const error = data.data;

return next(null, internals.utility.formatError(Object.assign(data, { error }), tags, this._settings));
}

if (!data.data) {
data.data = '(none)';
}
Expand Down
22 changes: 22 additions & 0 deletions test/index.js
Expand Up @@ -460,6 +460,28 @@ describe('GoodConsole', () => {
done();
});
});

it('returns a formatted string for "default" events with data as Error', { plan: 2 }, (done) => {

const reporter = new GoodConsole();
const out = new Streams.Writer();
const reader = new Streams.Reader();

reader.pipe(reporter).pipe(out);

const defaultEvent = Object.assign({}, internals.default);
defaultEvent.data = new Error('you logged an error');

reader.push(defaultEvent);
reader.push(null);

reader.once('end', () => {

expect(out.data).to.have.length(1);
expect(out.data[0].split('\n')[0]).to.be.equal('160318/013330.957, [request,user,info] message: you logged an error stack: Error: you logged an error');
done();
});
});
});
});
});

0 comments on commit e32cec6

Please sign in to comment.