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

Fix for Issue #31 #33

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -175,18 +175,13 @@ common.loggly = function () {
request(requestOptions, function (err, res, body) {
if (err) return onError(err);
statusCode = res.statusCode.toString();
if(statusCode === '403') isValidToken = false;
if (statusCode === '500' || statusCode === '503' || statusCode === '504') retryOnServerError(res);
if (statusCode === '200') {
arrRetryLogs.splice(0, 1);
totalRetries = 0;
}
if (Object.keys(failCodes).indexOf(statusCode) !== -1) {
if (statusCode !== '503' && statusCode !== '500' && statusCode !== '504') {
return onError((new Error('Loggly Error (' + statusCode + '): ' + failCodes[statusCode])));
if (statusCode === '200') {
arrRetryLogs.splice(0, 1);
totalRetries = 0;
success(res, body);
} else {
retryOnServerError(statusCode, res);
}
}
success(res, body);
});
}
catch (ex) {
@@ -211,18 +206,13 @@ common.loggly = function () {
request(requestOptions, function (err, res, body) {
if (err) return onError(err);
var statusCode = res.statusCode.toString();
if(statusCode === '403') isValidToken = false;
if (statusCode === '500' || statusCode === '503' || statusCode === '504') retryOnServerError(res);
if (statusCode === '200') {
arrRetryLogs.splice(0, arrSize);
totalRetries = 0;
success(res, body);
} else {
retryOnServerError(statusCode, res);
}
if (Object.keys(failCodes).indexOf(statusCode) !== -1) {
if (statusCode !== '503' && statusCode !== '500' && statusCode !== '504') {
return onError((new Error('Loggly Error (' + statusCode + '): ' + failCodes[statusCode])));
}
}
success(res, body);
});
}
catch (ex) {
@@ -257,22 +247,32 @@ common.loggly = function () {
//
//function to retry sending logs maximum 5 times if server error occurs
//
function retryOnServerError(err) {
if (!arrRetryLogs.length) return;
else {
function retryOnServerError(statusCode, err) {
if(statusCode === '403') isValidToken = false;
if (statusCode === '500' || statusCode === '503' || statusCode === '504') {
if (!arrRetryLogs.length) return onError(err);

if (notFailedOnServerError && totalRetries >= maxRetryAllowed) {
console.log('Failed after ' + totalRetries + ' retries on error - ' + statusCode, '"'+err.statusMessage+'"');
console.log('Failed after ' + totalRetries + ' retries on error - ' + statusCode, '"' + err.statusMessage + '"');
notFailedOnServerError = false;
arrRetryLogs.length = 0;
totalRetries = 0;
return onError(err)
}

while (isValidToken && totalRetries < maxRetryAllowed) {
console.log('Failed on error code ' + statusCode);
console.log('Retried ' + (totalRetries + 1) + ' time');
totalRetries++;
isBulk ? sendBulkLogs() : sendLogs();
}
}

if (Object.keys(failCodes).indexOf(statusCode) !== -1) {
if (statusCode !== '503' && statusCode !== '500' && statusCode !== '504') {
return onError((new Error('Loggly Error (' + statusCode + '): ' + failCodes[statusCode])));
}
}
}

//
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.