-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #337 from rollbar/propagate-message
[Fixes #336] Propagate message
- Loading branch information
Showing
8 changed files
with
94 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
var _ = require('./utility'); | ||
|
||
function itemToPayload(item, options, callback) { | ||
var payloadOptions = options.payload || {}; | ||
if (payloadOptions.body) { | ||
delete payloadOptions.body; | ||
} | ||
|
||
var data = _.extend(true, {}, item.data, payloadOptions); | ||
if (item._isUncaught) { | ||
data._isUncaught = true; | ||
} | ||
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, | ||
addMessageWithError: addMessageWithError | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* globals expect */ | ||
/* globals describe */ | ||
/* globals it */ | ||
|
||
var _ = require('../src/utility'); | ||
var t = require('../src/transforms'); | ||
|
||
function itemFromArgs(args) { | ||
var item = _.createItem(args); | ||
item.level = 'debug'; | ||
return item; | ||
} | ||
|
||
describe('itemToPayload', function() { | ||
it('ignores options.payload.body but merges in other payload options', function(done) { | ||
var args = ['a message', {custom: 'stuff'}]; | ||
var item = itemFromArgs(args); | ||
item.accessToken = 'abc123'; | ||
var options = { | ||
endpoint: 'api.rollbar.com', | ||
payload: {body: 'hey', x: 42} | ||
}; | ||
t.itemToPayload(item, options, function(e, i) { | ||
expect(i.body).to.not.eql('hey'); | ||
expect(i.x).to.eql(42); | ||
done(e); | ||
}); | ||
}); | ||
it('ignores handles trailing slash in endpoint', function(done) { | ||
var args = ['a message', {custom: 'stuff'}]; | ||
var item = itemFromArgs(args); | ||
item.accessToken = 'abc123'; | ||
item.data = {message: 'a message'}; | ||
var options = { | ||
endpoint: 'api.rollbar.com/' | ||
}; | ||
t.itemToPayload(item, options, function(e, i) { | ||
expect(i.message).to.eql('a message'); | ||
done(e); | ||
}); | ||
}); | ||
}); |