Skip to content

Commit fd3a0b0

Browse files
committed
Simplify some logic around the auth querystring
1 parent a62d0c4 commit fd3a0b0

File tree

2 files changed

+16
-26
lines changed

2 files changed

+16
-26
lines changed

src/raven.js

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ var _Raven = window.Raven,
2020
collectWindowErrors: true,
2121
tags: {},
2222
extra: {}
23-
};
23+
},
24+
authQueryString;
2425

2526
/*
2627
* The core Raven singleton
@@ -95,6 +96,8 @@ var Raven = {
9596

9697
TraceKit.collectWindowErrors = !!globalOptions.collectWindowErrors;
9798

99+
setAuthQueryString();
100+
98101
// return for chaining
99102
return Raven;
100103
},
@@ -392,23 +395,15 @@ function each(obj, callback) {
392395
}
393396
}
394397

395-
var cachedAuth;
396-
397-
function getAuthQueryString() {
398-
if (cachedAuth) return cachedAuth;
399398

400-
var qs = [
401-
'sentry_version=4',
402-
'sentry_client=raven-js/' + Raven.VERSION
403-
];
404-
if (globalKey) {
405-
qs.push('sentry_key=' + globalKey);
406-
}
407-
408-
cachedAuth = '?' + qs.join('&');
409-
return cachedAuth;
399+
function setAuthQueryString() {
400+
authQueryString =
401+
'?sentry_version=4' +
402+
'&sentry_client=raven-js/' + Raven.VERSION +
403+
'&sentry_key=' + globalKey;
410404
}
411405

406+
412407
function handleStackInfo(stackInfo, options) {
413408
var frames = [];
414409

@@ -622,7 +617,7 @@ function send(data) {
622617

623618
function makeRequest(data) {
624619
var img = new Image(),
625-
src = globalServer + getAuthQueryString() + '&sentry_data=' + encodeURIComponent(JSON.stringify(data));
620+
src = globalServer + authQueryString + '&sentry_data=' + encodeURIComponent(JSON.stringify(data));
626621

627622
img.onload = function success() {
628623
triggerEvent('success', {

test/raven.test.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
function flushRavenState() {
2-
cachedAuth = undefined;
2+
authQueryString = undefined;
33
hasJSON = !isUndefined(window.JSON);
44
lastCapturedException = undefined;
55
lastEventId = undefined;
@@ -221,16 +221,11 @@ describe('globals', function() {
221221
});
222222
});
223223

224-
describe('getAuthQueryString', function() {
224+
describe('setAuthQueryString', function() {
225225
it('should return a properly formatted string and cache it', function() {
226226
var expected = '?sentry_version=4&sentry_client=raven-js/<%= pkg.version %>&sentry_key=abc';
227-
assert.strictEqual(getAuthQueryString(), expected);
228-
assert.strictEqual(cachedAuth, expected);
229-
});
230-
231-
it('should return cached value when it exists', function() {
232-
cachedAuth = 'lol';
233-
assert.strictEqual(getAuthQueryString(), 'lol');
227+
setAuthQueryString();
228+
assert.strictEqual(authQueryString, expected);
234229
});
235230
});
236231

@@ -810,7 +805,7 @@ describe('globals', function() {
810805
describe('makeRequest', function() {
811806
it('should load an Image', function() {
812807
imageCache = [];
813-
this.sinon.stub(window, 'getAuthQueryString').returns('?lol');
808+
authQueryString = '?lol';
814809
globalServer = 'http://localhost/';
815810

816811
makeRequest({foo: 'bar'});

0 commit comments

Comments
 (0)