Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

leveraged the error formatter when data is an Error #86

Merged
merged 1 commit into from Feb 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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();
});
});
});
});
});