Skip to content

Commit

Permalink
Fix #331 Verbose logging was using the wrong key structure
Browse files Browse the repository at this point in the history
The queue gets the item to log that represents the data in the final payload structure of
```
{
  "access_token": "abc123",
  "data": { ... }
}
```

rather than the whole payload itself. The API object is responsible for wrapping that data object up
inside a structure like the above and then sending it. Thus the body of the item is a top level key
rather than nested under the data key.

Secondly, everyone wants the original error to be output if there is one isntead of just the
exception message, so make it so.
  • Loading branch information
rokob committed Jul 6, 2017
1 parent 27ba3a8 commit 3fb126e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,12 @@ Notifier.prototype.log = function(item, callback) {
return callback(new Error('Rollbar is not enabled'));
}

var originalError = item.err;
this._applyTransforms(item, function(err, i) {
if (err) {
return callback(err, null);
}
this.queue.addItem(i, callback);
this.queue.addItem(i, callback, originalError);
}.bind(this));
};

Expand Down Expand Up @@ -108,7 +109,7 @@ Notifier.prototype._applyTransforms = function(item, callback) {

transforms[transformIndex](i, options, cb);
};

cb(null, item);
};

Expand Down
14 changes: 8 additions & 6 deletions src/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ Queue.prototype.addPredicate = function(predicate) {
* in the case of a success, otherwise response will be null and error will have a value. If both
* error and response are null then the item was stopped by a predicate which did not consider this
* to be an error condition, but nonetheless did not send the item to the API.
* @param originalError - The original error before any transformations that is to be logged if any
*/
Queue.prototype.addItem = function(item, callback) {
Queue.prototype.addItem = function(item, callback, originalError) {
if (!callback || !_.isFunction(callback)) {
callback = function() { return; };
}
Expand All @@ -75,7 +76,7 @@ Queue.prototype.addItem = function(item, callback) {
callback();
return;
}
this._maybeLog(item);
this._maybeLog(item, originalError);
this.pendingRequests.push(item);
try {
this._makeApiRequest(item, function(err, resp) {
Expand Down Expand Up @@ -215,15 +216,16 @@ Queue.prototype._dequeuePendingRequest = function(item) {
}
};

Queue.prototype._maybeLog = function(item) {
Queue.prototype._maybeLog = function(data, originalError) {
if (this.logger && this.options.verbose) {
var message = _.get(item, 'data.body.trace.exception.message');
message = message || _.get(item, 'data.body.trace_chain.0.exception.message');
var message = originalError;
message = message || _.get(data, 'body.trace.exception.message');
message = message || _.get(data, 'body.trace_chain.0.exception.message');
if (message) {
this.logger.error(message);
return;
}
message = _.get(item, 'data.body.message.body');
message = _.get(data, 'body.message.body');
if (message) {
this.logger.log(message);
}
Expand Down

0 comments on commit 3fb126e

Please sign in to comment.