Handle server request errors (only retry on timeout) (refs: #343ba1)

This commit is contained in:
Paul van Tilburg 2012-02-14 23:50:00 +01:00
parent cefe991968
commit 851c870b16
1 changed files with 13 additions and 2 deletions

View File

@ -193,8 +193,19 @@ function update_drag_info(event, ui) {
function poll_server(timestamp) {
$.ajax({ url: "events?timestamp=" + timestamp,
success: handle_server_event,
error: function() { poll_server(timestamp) }, // FIXME; handle properly!
dataType: "json", timeout: 60000 });
error: function(event) {
switch (event.statusText) {
case "timeout":
// Got a timeout, retry with the same timestamp.
poll_server(timestamp);
break;
case "abort":
case "error":
// Lost connection to the server for some reason!
set_message("Lost contact to the server somehow! " +
"Reload this page to try to fix that.");
}},
dataType: "json", timeout: 60 * 1000 });
};
// Handle server events.