Skip to content
This repository has been archived by the owner on Nov 28, 2017. It is now read-only.

Commit

Permalink
better way to prevent overwritten base properties on errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
benbuckman committed Oct 29, 2015
1 parent 397bb36 commit 5f062c8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function EbayClientError(message, extraProps) {
Error.captureStackTrace(this, this.constructor);
this.name = this.constructor.name;
this.message = message;
_.extend(this, _.omit(extraProps, ['name', 'message']));
_.defaults(this, extraProps);
}
inherits(EbayClientError, Error);

Expand Down
5 changes: 3 additions & 2 deletions test/errors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,13 @@ describe('error classes', function() {
it('can\'t overwrite base properties with extra properties', function() {
var err = new errorClass('Original message', {
message: 'New message',
name: 'UhOh'
name: 'UhOh',
stack: 'ByeBye'
});

expect(err.message).to.equal('Original message');
expect(err.name).to.equal(errorClassName);

expect(err.stack).not.to.equal('ByeBye');
});

});
Expand Down

0 comments on commit 5f062c8

Please sign in to comment.