Skip to content

Commit 35934eb

Browse files
author
Javier Mendiara Cañardo
committed
[[FEAT]] Drop repeated info on toString
1 parent 2baa3e3 commit 35934eb

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

lib/index.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,13 @@ function toObject(error, withStack) {
5050
}
5151

5252
function toString(error, withStack) {
53-
var ret = [formatError(error)]
54-
.concat(getCauses(error).map(formatMessage))
55-
.join(': ');
56-
5753
if (withStack && error instanceof Error) {
58-
ret += '\n' + getFullErrorStack(error);
54+
return getFullErrorStack(error);
55+
} else {
56+
return [formatError(error)]
57+
.concat(getCauses(error).map(formatMessage))
58+
.join(': ')
5959
}
60-
61-
return ret;
6260
}
6361

6462
/*

test/toString.spec.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ describe('toString', function() {
2828
var err = new Error('foo');
2929
var obj = serializeError(err).toString(true);
3030

31-
expect(obj).to.be.eql('Error: foo' +
32-
'\n' + err.stack
33-
);
31+
expect(obj).to.be.eql(err.stack);
3432
});
3533

3634
describe('with cause', function() {
@@ -65,8 +63,7 @@ describe('toString', function() {
6563
err.cause = sandbox.stub().returns(err1);
6664
var obj = serializeError(err).toString(true);
6765

68-
expect(obj).to.be.eql('Error: foo: bar: baz' +
69-
'\n' + err.stack +
66+
expect(obj).to.be.eql(err.stack +
7067
'\nCaused by: ' + err1.stack +
7168
'\nCaused by: ' + err2
7269
);

0 commit comments

Comments
 (0)