Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ function makeConstructor(name, defaults) {
var ErrCtor = function() {
// call super
RestError.apply(this, arguments);
this.name = name;
};
util.inherits(ErrCtor, RestError);

Expand Down
18 changes: 12 additions & 6 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -554,11 +554,13 @@ describe('restify-errors node module.', function() {
assert.equal(err.cause(), underlyingErr);

// assert stringification
assert.equal(JSON.stringify(err), JSON.stringify({
var expectedJSON = {
code: 'Execution',
message: 'bad joystick input; ' +
'caused by Error: underlying error!'
}));
};
assert.equal(JSON.stringify(err), JSON.stringify(expectedJSON));
assert.equal(err.toString(), err.name + ': ' + expectedJSON.message);
});

it('should create custom error instance using options', function() {
Expand Down Expand Up @@ -591,11 +593,13 @@ describe('restify-errors node module.', function() {
assert.deepEqual(err.context.baz, [1,2,3]);

// assert stringification
assert.equal(JSON.stringify(err), JSON.stringify({
var expectedJSON = {
code: 'Execution',
message: 'bad joystick input; ' +
'caused by Error: underlying error!'
}));
};
assert.equal(JSON.stringify(err), JSON.stringify(expectedJSON));
assert.equal(err.toString(), err.name + ': ' + expectedJSON.message);
});

it('should create custom error using makeConstructor (with lower case Error name)', function() {
Expand All @@ -610,11 +614,13 @@ describe('restify-errors node module.', function() {
assert.equal(err instanceof restifyErrors.Executionerror, true);

// assert stringification
assert.equal(JSON.stringify(err), JSON.stringify({
var expectedJSON = {
code: 'Execution',
message: 'bad joystick input; ' +
'caused by Error: underlying error!'
}));
};
assert.equal(JSON.stringify(err), JSON.stringify(expectedJSON));
assert.equal(err.toString(), err.name + ': ' + expectedJSON.message);
});

it('should throw when creating a constructor that already exists', function() {
Expand Down