Skip to content
Closed
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
9 changes: 8 additions & 1 deletion lib/baseClasses/HttpError.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,17 @@ HttpError.prototype.toJSON = function toJSON() {
message = self.body.message;
}

return {
var resp = {
code: self.body.code,
message: message
};

// Add conext if we have it
if (self.context) {
resp.context = self.context;
}

return resp;
};


Expand Down
8 changes: 5 additions & 3 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ describe('restify-errors node module.', function() {

it('should create custom error instance', function() {
var underlyingErr = new Error('underlying error!');
var err = new restifyErrors.ExecutionError(underlyingErr, 'bad joystick input');
var err = new restifyErrors.ExecutionError(underlyingErr, {message: 'bad joystick input', context: {key: 'val'}});

assert.equal(err instanceof restifyErrors.ExecutionError, true);
assert.equal(err instanceof RestError, true);
Expand All @@ -557,7 +557,8 @@ describe('restify-errors node module.', function() {
var expectedJSON = {
code: 'Execution',
message: 'bad joystick input; ' +
'caused by Error: underlying error!'
'caused by Error: underlying error!',
context: {key: 'val'}
};
assert.equal(JSON.stringify(err), JSON.stringify(expectedJSON));
assert.equal(err.toString(), err.name + ': ' + expectedJSON.message);
Expand Down Expand Up @@ -596,7 +597,8 @@ describe('restify-errors node module.', function() {
var expectedJSON = {
code: 'Execution',
message: 'bad joystick input; ' +
'caused by Error: underlying error!'
'caused by Error: underlying error!',
context: {foo: 'bar', baz: [1,2,3]}
};
assert.equal(JSON.stringify(err), JSON.stringify(expectedJSON));
assert.equal(err.toString(), err.name + ': ' + expectedJSON.message);
Expand Down