Skip to content

Enabling Raven.debug will log outbound request data (refs #364) #368

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 19, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions src/raven.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,6 @@ var Raven = {
* @return {Raven}
*/
captureException: function(ex, options) {
if (!isSetup()) {
return Raven;
}

// If not an Error is passed through, recall as a message instead
if (!isError(ex)) return Raven.captureMessage(ex, options);

Expand Down Expand Up @@ -267,10 +263,6 @@ var Raven = {
* @return {Raven}
*/
captureMessage: function(msg, options) {
if (!isSetup()) {
return Raven;
}

// config() automagically converts ignoreErrors from a list to a RegExp so we need to test for an
// early call; we'll error on the side of logging anything called before configuration since it's
// probably something you should see:
Expand Down Expand Up @@ -699,8 +691,6 @@ function getHttpData() {
}

function send(data) {
if (!isSetup()) return;

var baseData = {
project: globalProject,
logger: globalOptions.logger,
Expand Down Expand Up @@ -757,13 +747,18 @@ function send(data) {


function makeRequest(data) {
var img = newImage(),
src = globalServer + authQueryString + '&sentry_data=' + encodeURIComponent(JSON.stringify(data));
var img,
src;

logDebug('debug', 'Raven about to send:', data);

if (!isSetup()) return;

img = newImage();
src = globalServer + authQueryString + '&sentry_data=' + encodeURIComponent(JSON.stringify(data));
if (globalOptions.crossOrigin || globalOptions.crossOrigin === '') {
img.crossOrigin = globalOptions.crossOrigin;
}

img.onload = function success() {
triggerEvent('success', {
data: data,
Expand All @@ -786,10 +781,14 @@ function newImage() {
return document.createElement('img');
}

var ravenNotConfiguredError;

function isSetup() {
if (!hasJSON) return false; // needs JSON support
if (!globalServer) {
logDebug('error', 'Error: Raven has not been configured.');
if (!ravenNotConfiguredError)
logDebug('error', 'Error: Raven has not been configured.');
ravenNotConfiguredError = true;
return false;
}
return true;
Expand Down
65 changes: 45 additions & 20 deletions test/raven.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ function flushRavenState() {
tags: {},
extra: {}
},
startTime = 0
;
startTime = 0;
ravenNotConfiguredError = undefined;

Raven.uninstall();
}
Expand Down Expand Up @@ -286,17 +286,31 @@ describe('globals', function() {
});

describe('isSetup', function() {
beforeEach(function () {
this.sinon.stub(window, 'logDebug');
});

it('should return false with no JSON support', function() {
globalServer = 'http://localhost/';
hasJSON = false;
assert.isFalse(isSetup());
});

it('should return false when Raven is not configured', function() {
hasJSON = true; // be explicit
describe('when Raven is not configured', function () {
it('should return false when Raven is not configured', function() {
hasJSON = true; // be explicit
globalServer = undefined;
assert.isFalse(isSetup());
});

it('should log an error message, the first time it is called', function () {
hasJSON = true;
globalServer = undefined;
this.sinon.stub(window, 'logDebug');
assert.isFalse(isSetup());
isSetup();
isSetup();
assert.isTrue(window.logDebug.calledWith('error', 'Error: Raven has not been configured.'))
assert.isTrue(window.logDebug.calledOnce);
});
});

it('should return true when everything is all gravy', function() {
Expand Down Expand Up @@ -327,7 +341,6 @@ describe('globals', function() {
Raven.debug = true;
this.sinon.stub(console, level);
logDebug(level, message, {}, 'foo');
assert.isTrue(console[level].calledOnce);
});
});

Expand Down Expand Up @@ -825,15 +838,6 @@ describe('globals', function() {
});

describe('send', function() {
it('should check `isSetup`', function() {
this.sinon.stub(window, 'isSetup').returns(false);
this.sinon.stub(window, 'makeRequest');

send();
assert.isTrue(window.isSetup.calledOnce);
assert.isFalse(window.makeRequest.calledOnce);
});

it('should build a good data payload', function() {
this.sinon.stub(window, 'isSetup').returns(true);
this.sinon.stub(window, 'makeRequest');
Expand Down Expand Up @@ -1096,6 +1100,25 @@ describe('globals', function() {
this.sinon.stub(window, 'newImage', function(){ var img = {}; imageCache.push(img); return img; });
})

it('should check `isSetup`', function() {
this.sinon.stub(window, 'isSetup').returns(false);
makeRequest({foo: 'bar'});
assert.isTrue(window.isSetup.called);
});

it('should not create the image if `isSetup` is false', function() {
this.sinon.stub(window, 'isSetup').returns(false);
makeRequest({foo: 'bar'});
assert.isFalse(window.newImage.called);
});

it('should log to console', function() {
this.sinon.stub(window, 'isSetup').returns(true);
this.sinon.stub(window, 'logDebug');
makeRequest({foo: 'bar'});
assert.isTrue(window.logDebug.called);
});

it('should load an Image', function() {
authQueryString = '?lol';
globalServer = 'http://localhost/';
Expand Down Expand Up @@ -1772,8 +1795,9 @@ describe('Raven (public API)', function() {
it('should not throw an error if not configured', function() {
this.sinon.stub(Raven, 'isSetup').returns(false);
this.sinon.stub(window, 'send')
Raven.captureMessage('foo');
assert.isFalse(window.send.called);
assert.doesNotThrow(function() {
Raven.captureMessage('foo');
});
});

});
Expand Down Expand Up @@ -1830,8 +1854,9 @@ describe('Raven (public API)', function() {
it('should not throw an error if not configured', function() {
this.sinon.stub(Raven, 'isSetup').returns(false);
this.sinon.stub(window, 'handleStackInfo')
Raven.captureException(new Error('err'));
assert.isFalse(window.handleStackInfo.called);
assert.doesNotThrow(function() {
Raven.captureException(new Error('err'));
});
});
});

Expand Down