Skip to content

Commit 441e55b

Browse files
committed
Enabling Raven.debug will log outbound request data
1 parent f361977 commit 441e55b

File tree

2 files changed

+29
-19
lines changed

2 files changed

+29
-19
lines changed

src/raven.js

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -750,18 +750,10 @@ function makeRequest(data) {
750750
var img,
751751
src;
752752

753-
if (isSetup()) {
754-
logDebug('debug', 'Raven about to send:', data);
755-
}
756-
else {
757-
var ravenDebugOriginal = Raven.debug;
758-
//Ugly, but now that logDebug supports variadic arguments, there is little other choice
759-
//except duplicating the logDebug function.
760-
Raven.debug = true;
761-
logDebug('log', 'If configured, Raven would send:', data);
762-
Raven.debug = ravenDebugOriginal;
763-
return;
764-
}
753+
logDebug('debug', 'Raven about to send:', data);
754+
755+
if (!isSetup()) return;
756+
765757
img = newImage();
766758
src = globalServer + authQueryString + '&sentry_data=' + encodeURIComponent(JSON.stringify(data));
767759
if (globalOptions.crossOrigin || globalOptions.crossOrigin === '') {
@@ -789,10 +781,14 @@ function newImage() {
789781
return document.createElement('img');
790782
}
791783

784+
var ravenNotConfiguredError;
785+
792786
function isSetup() {
793787
if (!hasJSON) return false; // needs JSON support
794788
if (!globalServer) {
795-
logDebug('error', 'Error: Raven has not been configured.');
789+
if (!ravenNotConfiguredError)
790+
logDebug('error', 'Error: Raven has not been configured.');
791+
ravenNotConfiguredError = true;
796792
return false;
797793
}
798794
return true;

test/raven.test.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ function flushRavenState() {
1919
tags: {},
2020
extra: {}
2121
},
22-
startTime = 0
23-
;
22+
startTime = 0;
23+
ravenNotConfiguredError = undefined;
2424

2525
Raven.uninstall();
2626
}
@@ -286,17 +286,31 @@ describe('globals', function() {
286286
});
287287

288288
describe('isSetup', function() {
289+
beforeEach(function () {
290+
this.sinon.stub(window, 'logDebug');
291+
});
292+
289293
it('should return false with no JSON support', function() {
290294
globalServer = 'http://localhost/';
291295
hasJSON = false;
292296
assert.isFalse(isSetup());
293297
});
294298

295-
it('should return false when Raven is not configured', function() {
296-
hasJSON = true; // be explicit
299+
describe('when Raven is not configured', function () {
300+
it('should return false when Raven is not configured', function() {
301+
hasJSON = true; // be explicit
302+
globalServer = undefined;
303+
assert.isFalse(isSetup());
304+
});
305+
306+
it('should log an error message, the first time it is called', function () {
307+
hasJSON = true;
297308
globalServer = undefined;
298-
this.sinon.stub(window, 'logDebug');
299-
assert.isFalse(isSetup());
309+
isSetup();
310+
isSetup();
311+
assert.isTrue(window.logDebug.calledWith('error', 'Error: Raven has not been configured.'))
312+
assert.isTrue(window.logDebug.calledOnce);
313+
});
300314
});
301315

302316
it('should return true when everything is all gravy', function() {

0 commit comments

Comments
 (0)