Skip to content

Commit 3ceae83

Browse files
committed
Merge pull request #312 from acdha/capture-message-ignore-errors
captureMessage() uses global ignoreErrors config
2 parents 43dd05d + d8df8dc commit 3ceae83

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/raven.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,13 @@ var Raven = {
261261
* @return {Raven}
262262
*/
263263
captureMessage: function(msg, options) {
264+
// config() automagically converts ignoreErrors from a list to a RegExp so we need to test for an
265+
// early call; we'll error on the side of logging anything called before configuration since it's
266+
// probably something you should see:
267+
if (!!globalOptions.ignoreErrors.test && globalOptions.ignoreErrors.test(msg)) {
268+
return;
269+
}
270+
264271
// Fire away!
265272
send(
266273
objectMerge({

test/raven.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,6 +1594,18 @@ describe('Raven (public API)', function() {
15941594
Raven.captureMessage('lol');
15951595
assert.equal(Raven.lastEventId(), 'abc123');
15961596
});
1597+
1598+
it('should respect `ignoreErrors`', function() {
1599+
this.sinon.stub(window, 'send');
1600+
1601+
globalOptions.ignoreErrors = joinRegExp(['e1', 'e2']);
1602+
Raven.captureMessage('e1');
1603+
assert.isFalse(window.send.called);
1604+
Raven.captureMessage('e2');
1605+
assert.isFalse(window.send.called);
1606+
Raven.captureMessage('Non-ignored error');
1607+
assert.isTrue(window.send.calledOnce);
1608+
});
15971609
});
15981610

15991611
describe('.captureException', function() {

0 commit comments

Comments
 (0)