Skip to content
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

Added gitignore and added retries for failed batch attempts #43

Open
wants to merge 8 commits into
base: master
from

Put error handler in onreadystatechange

  • Loading branch information
Clark, Jason Clark, Jason
Clark, Jason authored and Clark, Jason committed Aug 3, 2016
commit 04bc3d37de54230056350d21c26ac4b0951cb558
@@ -165,23 +165,33 @@
xmlHttp.open('POST', this.inputUrl, true); //true for asynchronous request
xmlHttp.setRequestHeader('Content-Type', 'text/plain');
xmlHttp.send(JSON.stringify(data));
if(postTimeout) {
clearTimeout(postTimeout);
}
xmlHttp.onreadystatechange = function() {
if(xmlHttp.readyState === 4 && xmlHttp.status !== 200) {
if(attemptCounter <= 12) {
console.log("Failed to log to loggly because of a network condition.");
console.log("Will attempt to log again in 5 seconds.");

postTimeout = setTimeout(this.track(data, attemptCounter + 1), 5000);
} else {
console.log("Loggly has attempted to log this data for the last minute and failed. Ceasing" +
" attempts to log.");
console.log("Failed log data:", data);

clearTimeout(postTimeout);
}
} else if (xmlHttp.status === 200) {
if(postTimeout) {
clearTimeout(postTimeout);
attemptCounter = 0;
}
}
};

} catch (ex) {
if(attemptCounter <= 12) {
if (window && window.console && typeof window.console.log === 'function') {
console.log("Failed to log to loggly because of this exception:\n" + ex);
console.log("Failed log data:", data);
console.log("Loggly will attempt in 5 seconds to log this again.");
}
postTimeout = setTimeout(this.track(data, attemptCounter + 1), 5000);
} else {
clearTimeout(postTimeout);
console.log("Loggly has attempted to log this data for the last minute and failed. Ceasing" +
" attempts to log.");
if (window && window.console && typeof window.console.log === 'function') {
console.log("Failed to log to loggly because of this exception:\n" + ex);
console.log("Failed log data:", data);
console.log("Loggly will attempt in 5 seconds to log this again.");
}
}
},
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.