Skip to content

Commit f4cac49

Browse files
committed
Expose getter/setter for dataCallback and shouldSendCallback
1 parent 4391242 commit f4cac49

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

src/raven.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,32 @@ var Raven = {
326326
return Raven;
327327
},
328328

329+
/*
330+
* Set the dataCallback option
331+
*
332+
* @param {function} callback The callback to run which allows the
333+
* data blob to be mutated before sending
334+
* @return {Raven}
335+
*/
336+
setDataCallback: function(callback) {
337+
globalOptions.dataCallback = callback;
338+
339+
return Raven;
340+
},
341+
342+
/*
343+
* Set the shouldSendCallback option
344+
*
345+
* @param {function} callback The callback to run which allows
346+
* introspecting the blob before sending
347+
* @return {Raven}
348+
*/
349+
setShouldSendCallback: function(callback) {
350+
globalOptions.shouldSendCallback = callback;
351+
352+
return Raven;
353+
},
354+
329355
/*
330356
* Get the latest raw exception that was captured by Raven.
331357
*

test/raven.test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1604,6 +1604,36 @@ describe('Raven (public API)', function() {
16041604
});
16051605
});
16061606

1607+
describe('.setDataCallback', function() {
1608+
it('should set the globalOptions.dataCallback attribute', function() {
1609+
var foo = function(){};
1610+
Raven.setDataCallback(foo);
1611+
assert.equal(globalOptions.dataCallback, foo);
1612+
});
1613+
1614+
it('should clear globalOptions.dataCallback with no arguments', function() {
1615+
var foo = function(){};
1616+
globalOptions.dataCallback = foo;
1617+
Raven.setDataCallback();
1618+
assert.isUndefined(globalOptions.dataCallback);
1619+
});
1620+
});
1621+
1622+
describe('.setShouldSendCallback', function() {
1623+
it('should set the globalOptions.shouldSendCallback attribute', function() {
1624+
var foo = function(){};
1625+
Raven.setShouldSendCallback(foo);
1626+
assert.equal(globalOptions.shouldSendCallback, foo);
1627+
});
1628+
1629+
it('should clear globalOptions.shouldSendCallback with no arguments', function() {
1630+
var foo = function(){};
1631+
globalOptions.shouldSendCallback = foo;
1632+
Raven.setShouldSendCallback();
1633+
assert.isUndefined(globalOptions.shouldSendCallback);
1634+
});
1635+
});
1636+
16071637
describe('.captureMessage', function() {
16081638
it('should work as advertised', function() {
16091639
this.sinon.stub(window, 'send');

0 commit comments

Comments
 (0)