Skip to content

Commit

Permalink
Sanitize but log stack traces from errors sent to client
Browse files Browse the repository at this point in the history
  • Loading branch information
avital committed Jun 3, 2016
1 parent 20ee6bd commit 7872d52
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions lib/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,24 @@ Agent.prototype._sendOps = function(collection, id, ops) {

Agent.prototype._reply = function(request, err, message) {
if (err) {
request.error = (typeof err === 'string') ?
{message: err} :
{code: err.code, message: err.message, stack: err.stack};
if (typeof err === 'string') {
request.error = {message: err};
} else {
if (err.stack) {
// Log stack trace on the server
var message = 'Error: ' + err.message;
if (err.code) message = message + ' (' + err.code + ')';
console.warn(message);
console.warn(err.stack);
console.warn();

// Then hide stack trace from client
request.error = JSON.parse(JSON.stringify(err));
delete request.error.stack;
} else {
request.error = err;
}
}
this.send(request);
return;
}
Expand Down

0 comments on commit 7872d52

Please sign in to comment.