Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
Fix #5277, turn down logging if sendEvent fails
Browse files Browse the repository at this point in the history
This also turns off sending events for the session if it ever gets a 410 Gone response
  • Loading branch information
ianb committed Jan 4, 2019
1 parent 0318782 commit ffd7294
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions webextension/background/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ this.analytics = (function() {

let telemetryPrefKnown = false;
let telemetryEnabled;
// If we ever get a 410 Gone response from the server, we'll stop trying to send events for the rest
// of the session
let hasReturnedGone = false;

const EVENT_BATCH_DURATION = 1000; // ms for setTimeout
let pendingEvents = [];
Expand Down Expand Up @@ -110,6 +113,10 @@ this.analytics = (function() {
for (const [gaField, value] of Object.entries(abTests)) {
options[gaField] = value;
}
if (hasReturnedGone) {
// We don't want to save or send the events anymore
return Promise.resolve();
}
pendingEvents.push({
eventTime: Date.now(),
event: eventCategory,
Expand Down Expand Up @@ -307,15 +314,17 @@ this.analytics = (function() {
}

function fetchWatcher(request) {
catcher.watchPromise(
request.then(response => {
if (!response.ok) {
throw new Error(`Bad response from ${request.url}: ${response.status} ${response.statusText}`);
}
return response;
}),
true
);
request.then(response => {
if (response.status === 410) { // Gone
hasReturnedGone = true;
pendingEvents = [];
}
if (!response.ok) {
log.debug(`Error code in event response: ${response.status} ${response.statusText}`);
}
}).catch(error => {
log.debug(`Error event in response: ${error}`);
});
}

return exports;
Expand Down

0 comments on commit ffd7294

Please # to comment.