Skip to content

Refactor makeRequest to prepare to be overridden #379

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
Sep 15, 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
78 changes: 43 additions & 35 deletions src/raven.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ var _Raven = window.Raven,
maxMessageLength: 100,
extra: {}
},
authQueryString,
isRavenInstalled = false,
objectPrototype = Object.prototype,
// capture references to window.console *and* all its methods first
Expand Down Expand Up @@ -114,8 +113,6 @@ var Raven = {

TraceKit.collectWindowErrors = !!globalOptions.collectWindowErrors;

setAuthQueryString();

// return for chaining
return Raven;
},
Expand Down Expand Up @@ -508,15 +505,6 @@ function each(obj, callback) {
}
}


function setAuthQueryString() {
authQueryString =
'?sentry_version=4' +
'&sentry_client=raven-js/' + Raven.VERSION +
'&sentry_key=' + globalKey;
}


function handleStackInfo(stackInfo, options) {
var frames = [];

Expand Down Expand Up @@ -748,35 +736,46 @@ function send(data) {
// Set lastEventId after we know the error should actually be sent
lastEventId = data.event_id || (data.event_id = uuid4());

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

if (!isSetup()) return;

function makeRequest(data) {
var img,
src;
makeRequest({
url: globalServer,
auth: {
sentry_version: '4',
sentry_client: 'raven-js/' + Raven.VERSION,
sentry_key: globalKey
},
data: data,
options: globalOptions,
onSuccess: function success() {
triggerEvent('success', {
data: data,
src: globalServer
});
},
onError: function failure() {
triggerEvent('failure', {
data: data,
src: globalServer
});
}
});
}

logDebug('debug', 'Raven about to send:', data);
function makeRequest(opts) {
// Tack on sentry_data to auth options, which get urlencoded
opts.auth.sentry_data = JSON.stringify(opts.data);

if (!isSetup()) return;
var img = newImage(),
src = opts.url + '?' + urlencode(opts.auth);

img = newImage();
src = globalServer + authQueryString + '&sentry_data=' + encodeURIComponent(JSON.stringify(data));
if (globalOptions.crossOrigin || globalOptions.crossOrigin === '') {
img.crossOrigin = globalOptions.crossOrigin;
if (opts.options.crossOrigin || opts.options.crossOrigin === '') {
img.crossOrigin = opts.options.crossOrigin;
}
img.onload = function success() {
triggerEvent('success', {
data: data,
src: src
});
};
img.onerror = img.onabort = function failure() {
triggerEvent('failure', {
data: data,
src: src
});
};
img.onload = opts.onSuccess;
img.onerror = img.onabort = opts.onError;
img.src = src;
}

Expand Down Expand Up @@ -870,4 +869,13 @@ function afterLoad() {
Raven.config(RavenConfig.dsn, RavenConfig.config).install();
}
}

function urlencode(o) {
var pairs = [];
each(o, function(key, value) {
pairs.push(encodeURIComponent(key) + '=' + encodeURIComponent(value));
});
return pairs.join('&');
}

afterLoad();
Loading