Skip to content

Commit

Permalink
if we have a message and a stack trace, add the message to the extra …
Browse files Browse the repository at this point in the history
…data attached to the stack trace
  • Loading branch information
rokob committed Jul 12, 2017
1 parent 9681f1c commit 1e1ae05
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions sdks/rollbar.js/src/browser/rollbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ function addTransformsToNotifier(notifier) {
.addTransform(transforms.addClientInfo(window))
.addTransform(transforms.addPluginInfo(window))
.addTransform(transforms.addBody)
.addTransform(sharedTransforms.addMessageWithError)
.addTransform(transforms.scrubPayload)
.addTransform(transforms.userTransform)
.addTransform(sharedTransforms.itemToPayload);
Expand Down
2 changes: 1 addition & 1 deletion sdks/rollbar.js/src/browser/transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ function addBodyTrace(item, options, callback) {
};

if (description) {
trace.exception.description = description || 'uncaught exception';
trace.exception.description = description;
}

// Transform a TraceKit stackInfo object into a Rollbar trace
Expand Down
1 change: 1 addition & 0 deletions sdks/rollbar.js/src/server/rollbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ function addTransformsToNotifier(notifier) {
.addTransform(transforms.baseData)
.addTransform(transforms.handleItemWithError)
.addTransform(transforms.addBody)
.addTransform(sharedTransforms.addMessageWithError)
.addTransform(transforms.addRequestData)
.addTransform(transforms.scrubPayload)
.addTransform(sharedTransforms.itemToPayload);
Expand Down
27 changes: 26 additions & 1 deletion sdks/rollbar.js/src/transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,31 @@ function itemToPayload(item, options, callback) {
callback(null, data);
}

function addMessageWithError(item, options, callback) {
if (!item.message) {
callback(null, item);
return;
}
var tracePath = 'data.body.trace_chain.0';
var trace = _.get(item, tracePath);
if (!trace) {
tracePath = 'data.body.trace';
trace = _.get(item, tracePath);
}
if (trace) {
if (!(trace.exception && trace.exception.description)) {
_.set(item, tracePath+'.exception.description', item.message);
callback(null, item);
return;
}
var extra = _.get(item, tracePath+'.extra') || {};
var newExtra = _.extend(true, {}, extra, {message: item.message});
_.set(item, tracePath+'.extra', newExtra);
}
callback(null, item);
}

module.exports = {
itemToPayload: itemToPayload
itemToPayload: itemToPayload,
addMessageWithError: addMessageWithError
};

0 comments on commit 1e1ae05

Please sign in to comment.