Skip to content

Commit ee96db9

Browse files
committed
Log to console what would be sent to the server when raven isn't configured. Helps with local debugging of applications using raven.js
Conflicts: src/raven.js
1 parent 4ab2609 commit ee96db9

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

src/raven.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,6 @@ var Raven = {
232232
* @return {Raven}
233233
*/
234234
captureException: function(ex, options) {
235-
if (!isSetup()) {
236-
return Raven;
237-
}
238-
239235
// If not an Error is passed through, recall as a message instead
240236
if (!isError(ex)) return Raven.captureMessage(ex, options);
241237

@@ -267,10 +263,6 @@ var Raven = {
267263
* @return {Raven}
268264
*/
269265
captureMessage: function(msg, options) {
270-
if (!isSetup()) {
271-
return Raven;
272-
}
273-
274266
// config() automagically converts ignoreErrors from a list to a RegExp so we need to test for an
275267
// early call; we'll error on the side of logging anything called before configuration since it's
276268
// probably something you should see:
@@ -699,8 +691,6 @@ function getHttpData() {
699691
}
700692

701693
function send(data) {
702-
if (!isSetup()) return;
703-
704694
var baseData = {
705695
project: globalProject,
706696
logger: globalOptions.logger,
@@ -752,7 +742,12 @@ function send(data) {
752742
// Set lastEventId after we know the error should actually be sent
753743
lastEventId = data.event_id || (data.event_id = uuid4());
754744

755-
makeRequest(data);
745+
if (isSetup()) {
746+
makeRequest(data);
747+
}
748+
else {
749+
console.log("If configured, raven.js would send: ", data);
750+
}
756751
}
757752

758753

test/raven.test.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,20 @@ describe('globals', function() {
10861086
extra: {'session:duration': 100}
10871087
});
10881088
});
1089+
1090+
it('should log to console if not configured', function() {
1091+
this.sinon.stub(window, 'isSetup').returns(false);
1092+
this.sinon.stub(console, 'log');
1093+
send({foo: 'bar'});
1094+
assert.isTrue(console.log.called);
1095+
});
1096+
1097+
it('should NOT log to console if configured', function() {
1098+
this.sinon.stub(window, 'isSetup').returns(true);
1099+
this.sinon.stub(console, 'log');
1100+
send({foo: 'bar'});
1101+
assert.isFalse(console.log.called);
1102+
});
10891103
});
10901104

10911105
describe('makeRequest', function() {
@@ -1772,8 +1786,9 @@ describe('Raven (public API)', function() {
17721786
it('should not throw an error if not configured', function() {
17731787
this.sinon.stub(Raven, 'isSetup').returns(false);
17741788
this.sinon.stub(window, 'send')
1775-
Raven.captureMessage('foo');
1776-
assert.isFalse(window.send.called);
1789+
assert.doesNotThrow(function() {
1790+
Raven.captureMessage('foo');
1791+
});
17771792
});
17781793

17791794
});
@@ -1830,8 +1845,9 @@ describe('Raven (public API)', function() {
18301845
it('should not throw an error if not configured', function() {
18311846
this.sinon.stub(Raven, 'isSetup').returns(false);
18321847
this.sinon.stub(window, 'handleStackInfo')
1833-
Raven.captureException(new Error('err'));
1834-
assert.isFalse(window.handleStackInfo.called);
1848+
assert.doesNotThrow(function() {
1849+
Raven.captureException(new Error('err'));
1850+
});
18351851
});
18361852
});
18371853

0 commit comments

Comments
 (0)