Skip to content

Commit 21526f8

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 6768e4a commit 21526f8

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
@@ -231,10 +231,6 @@ var Raven = {
231231
* @return {Raven}
232232
*/
233233
captureException: function(ex, options) {
234-
if (!isSetup()) {
235-
return Raven;
236-
}
237-
238234
// If not an Error is passed through, recall as a message instead
239235
if (!isError(ex)) return Raven.captureMessage(ex, options);
240236

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

700692
function send(data) {
701-
if (!isSetup()) return;
702-
703693
var baseData = {
704694
project: globalProject,
705695
logger: globalOptions.logger,
@@ -751,7 +741,12 @@ function send(data) {
751741
// Set lastEventId after we know the error should actually be sent
752742
lastEventId = data.event_id || (data.event_id = uuid4());
753743

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

757752

test/raven.test.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,6 +1078,20 @@ describe('globals', function() {
10781078
extra: {'session:duration': 100}
10791079
});
10801080
});
1081+
1082+
it('should log to console if not configured', function() {
1083+
this.sinon.stub(window, 'isSetup').returns(false);
1084+
this.sinon.stub(console, 'log');
1085+
send({foo: 'bar'});
1086+
assert.isTrue(console.log.called);
1087+
});
1088+
1089+
it('should NOT log to console if configured', function() {
1090+
this.sinon.stub(window, 'isSetup').returns(true);
1091+
this.sinon.stub(console, 'log');
1092+
send({foo: 'bar'});
1093+
assert.isFalse(console.log.called);
1094+
});
10811095
});
10821096

10831097
describe('makeRequest', function() {
@@ -1732,8 +1746,9 @@ describe('Raven (public API)', function() {
17321746
it('should not throw an error if not configured', function() {
17331747
this.sinon.stub(Raven, 'isSetup').returns(false);
17341748
this.sinon.stub(window, 'send')
1735-
Raven.captureMessage('foo');
1736-
assert.isFalse(window.send.called);
1749+
assert.doesNotThrow(function() {
1750+
Raven.captureMessage('foo');
1751+
});
17371752
});
17381753

17391754
});
@@ -1790,8 +1805,9 @@ describe('Raven (public API)', function() {
17901805
it('should not throw an error if not configured', function() {
17911806
this.sinon.stub(Raven, 'isSetup').returns(false);
17921807
this.sinon.stub(window, 'handleStackInfo')
1793-
Raven.captureException(new Error('err'));
1794-
assert.isFalse(window.handleStackInfo.called);
1808+
assert.doesNotThrow(function() {
1809+
Raven.captureException(new Error('err'));
1810+
});
17951811
});
17961812
});
17971813

0 commit comments

Comments
 (0)