big rework of error handling on requests
- central point for checking for 'error: "out of date"' response from server - in 'out of date' state, an error dialog is shown and no further requests are sent to the server - request queue has central point for request adding - now request count is accurate, not just for COMM requests - request error count is cleared after a period of no requests failing
This commit is contained in:
parent
21463ca392
commit
c8fd938cd3
@ -132,8 +132,6 @@ window.chat.requestFaction = function(getOlderMsgs, isRetry) {
|
||||
? function() { window.chat._requestFactionRunning = false; }
|
||||
: function() { window.chat.requestFaction(getOlderMsgs, true) }
|
||||
);
|
||||
|
||||
requests.add(r);
|
||||
}
|
||||
|
||||
|
||||
@ -183,8 +181,6 @@ window.chat.requestPublic = function(getOlderMsgs, isRetry) {
|
||||
? function() { window.chat._requestPublicRunning = false; }
|
||||
: function() { window.chat.requestPublic(getOlderMsgs, true) }
|
||||
);
|
||||
|
||||
requests.add(r);
|
||||
}
|
||||
|
||||
window.chat._public = {data:{}, oldestTimestamp:-1, newestTimestamp:-1};
|
||||
|
@ -11,27 +11,9 @@ window.updateGameScore = function(data) {
|
||||
return;
|
||||
}
|
||||
|
||||
// hacky - but here is as good as any for a location
|
||||
// tne niantic servers include a 'version' parameter with the requests. this is changed for any site update they
|
||||
// roll out, even when the protocol has no changes at all. (and sometimes when there's no other client javascript
|
||||
// changes of any kind!)
|
||||
if (data.error || (data.indexOf && data.indexOf('"error"') != -1)) {
|
||||
if (data.error == 'out of date') {
|
||||
dialog({
|
||||
title: 'Reload IITC',
|
||||
html: '<p>IITC is using an outdated version code. This will happen when Niantic update the standard intel site.</p>'
|
||||
+'<p>You need to reload the page to get the updated changes.</p>'
|
||||
+'<p>If you have just reloaded the page, then an old version of the standard site script is cached somewhere.'
|
||||
+'In this case, try clearing your cache, or waiting 15-30 minutes for the stale data to expire.</p>',
|
||||
buttons: {
|
||||
'RELOAD': function() { window.location.reload(); }
|
||||
}
|
||||
});
|
||||
return;
|
||||
|
||||
} else {
|
||||
console.error('game score failed to load');
|
||||
}
|
||||
if (data && data.error) {
|
||||
// TODO? better retry handling in here...
|
||||
console.error('game score failed to load');
|
||||
}
|
||||
|
||||
window.updateGameScoreFailCount = 0;
|
||||
@ -47,5 +29,6 @@ window.updateGameScore = function(data) {
|
||||
// help cursor via “#gamestat span”
|
||||
$('#gamestat').attr('title', 'Resistance:\t'+r+' MindUnits\nEnlightened:\t'+e+' MindUnits');
|
||||
|
||||
// TODO: idle handling - don't refresh when IITC is idle!
|
||||
window.setTimeout('window.updateGameScore', REFRESH_GAME_SCORE*1000);
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
|
||||
// posts AJAX request to Ingress API.
|
||||
// action: last part of the actual URL, the rpc/dashboard. is
|
||||
// added automatically
|
||||
@ -7,26 +8,107 @@
|
||||
// success: method to call on success. See jQuery API docs for avail-
|
||||
// able arguments: http://api.jquery.com/jQuery.ajax/
|
||||
// error: see above. Additionally it is logged if the request failed.
|
||||
window.postAjax = function(action, data, success, error) {
|
||||
window.postAjax = function(action, data, successCallback, errorCallback) {
|
||||
// state management functions... perhaps should be outside of this func?
|
||||
|
||||
// var remove = function(data, textStatus, jqXHR) { window.requests.remove(jqXHR); };
|
||||
// var errCnt = function(jqXHR) { window.failedRequestCount++; window.requests.remove(jqXHR); };
|
||||
|
||||
if (window.latestFailedRequestTime && window.latestFailedRequestTime < Date.now()-120*1000) {
|
||||
// no errors in the last two minutes - clear the error count
|
||||
window.failedRequestCount = 0;
|
||||
window.latestFailedRequestTime = undefined;
|
||||
}
|
||||
|
||||
var onError = function(jqXHR, textStatus, errorThrown) {
|
||||
window.requests.remove(jqXHR);
|
||||
window.failedRequestCount++;
|
||||
|
||||
window.latestFailedRequestTime = Date.now();
|
||||
|
||||
// pass through to the user error func, if one exists
|
||||
if (errorCallback) {
|
||||
errorCallback(jqXHR, textStatus, errorThrown);
|
||||
}
|
||||
};
|
||||
|
||||
var onSuccess = function(data, textStatus, jqXHR) {
|
||||
window.requests.remove(jqXHR);
|
||||
|
||||
// the Niantic server can return a HTTP success, but the JSON response contains an error. handle that sensibly
|
||||
if (data && data.error && data.error == 'out of date') {
|
||||
window.failedRequestCount++;
|
||||
// let's call the error callback in thos case...
|
||||
if (errorCallback) {
|
||||
errorCallback(jqXHR, textStatus, "data.error == 'out of date'");
|
||||
}
|
||||
|
||||
window.outOfDateUserPrompt();
|
||||
} else {
|
||||
successCallback(data, textStatus, jqXHR);
|
||||
}
|
||||
};
|
||||
|
||||
// we set this flag when we want to block all requests due to having an out of date CURRENT_VERSION
|
||||
if (window.blockOutOfDateRequests) {
|
||||
window.failedRequestCount++;
|
||||
window.latestFailedRequestTime = Date.now();
|
||||
|
||||
// call the error callback, if one exists
|
||||
if (errorCallback) {
|
||||
// NOTE: error called on a setTimeout - as it won't be expected to be synchronous
|
||||
// ensures no recursion issues if the error handler immediately resends the request
|
||||
setTimeout(function(){errorCallback(null, undefined, "window.blockOutOfDateRequests is set");}, 10);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
var versionStr = nemesis.dashboard.config.CURRENT_VERSION;
|
||||
var post_data = JSON.stringify($.extend({}, data, {v: versionStr, b: "", c: ""}));
|
||||
|
||||
var remove = function(data, textStatus, jqXHR) { window.requests.remove(jqXHR); };
|
||||
var errCnt = function(jqXHR) { window.failedRequestCount++; window.requests.remove(jqXHR); };
|
||||
var result = $.ajax({
|
||||
url: '/r/'+action,
|
||||
type: 'POST',
|
||||
data: post_data,
|
||||
context: data,
|
||||
dataType: 'json',
|
||||
success: [remove, success],
|
||||
error: error ? [errCnt, error] : errCnt,
|
||||
success: [onSuccess],
|
||||
error: [onError],
|
||||
contentType: 'application/json; charset=utf-8',
|
||||
beforeSend: function(req) {
|
||||
req.setRequestHeader('X-CSRFToken', readCookie('csrftoken'));
|
||||
}
|
||||
});
|
||||
result.action = action;
|
||||
|
||||
requests.add(result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
window.outOfDateUserPrompt = function()
|
||||
{
|
||||
// we block all requests while the dialog is open.
|
||||
if (!window.blockOutOfDateRequests) {
|
||||
window.blockOutOfDateRequests = true;
|
||||
|
||||
dialog({
|
||||
title: 'Reload IITC',
|
||||
html: '<p>IITC is using an outdated version code. This will happen when Niantic update the standard intel site.</p>'
|
||||
+'<p>You need to reload the page to get the updated changes.</p>'
|
||||
+'<p>If you have just reloaded the page, then an old version of the standard site script is cached somewhere.'
|
||||
+'In this case, try clearing your cache, or waiting 15-30 minutes for the stale data to expire.</p>',
|
||||
buttons: {
|
||||
'RELOAD': function() { window.location.reload(); }
|
||||
},
|
||||
close: function(event, ui) {
|
||||
delete window.blockOutOfDateRequests;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user