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
12 changes: 10 additions & 2 deletions src/raven.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,12 +455,20 @@ Raven.prototype = {
* @return {Raven}
*/
captureMessage: function(msg, options) {
// Convert the message into a string
var exceptionMessage;
if (typeof msg === 'object' && msg !== null) {
exceptionMessage = JSON.stringify(msg);
} else {
exceptionMessage = '' + msg;
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved string convert logic before the ignore logic, so user's can ignore on custom objects


// config() automagically converts ignoreErrors from a list to a RegExp so we need to test for an
// early call; we'll error on the side of logging anything called before configuration since it's
// probably something you should see:
if (
!!this._globalOptions.ignoreErrors.test &&
this._globalOptions.ignoreErrors.test(msg)
this._globalOptions.ignoreErrors.test(exceptionMessage)
) {
return;
}
Expand All @@ -469,7 +477,7 @@ Raven.prototype = {

var data = objectMerge(
{
message: msg + '' // Make sure it's actually a string
message: exceptionMessage
},
options
);
Expand Down
29 changes: 25 additions & 4 deletions test/raven.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2835,15 +2835,36 @@ describe('Raven (public API)', function() {
}
]);
});

it('should coerce message to a string', function() {
it('should coerce object message to a json string', function() {
this.sinon.stub(Raven, 'isSetup').returns(true);
this.sinon.stub(Raven, '_send');
Raven.captureMessage({foo: 'bar'});
assert.isTrue(Raven._send.called);
assert.deepEqual(Raven._send.lastCall.args, [
{
message: '{"foo":"bar"}'
}
]);
});
it('should coerce array message to a json string', function() {
this.sinon.stub(Raven, 'isSetup').returns(true);
this.sinon.stub(Raven, '_send');
Raven.captureMessage([1, 2, 3]);
assert.isTrue(Raven._send.called);
assert.deepEqual(Raven._send.lastCall.args, [
{
message: '[1,2,3]'
}
]);
});
it('should coerce number to a string', function() {
this.sinon.stub(Raven, 'isSetup').returns(true);
this.sinon.stub(Raven, '_send');
Raven.captureMessage({});
Raven.captureMessage(56);
assert.isTrue(Raven._send.called);
assert.deepEqual(Raven._send.lastCall.args, [
{
message: '[object Object]'
message: '56'
}
]);
});
Expand Down