Tell the user about AJAX errors.

Set AJAX options: 5s timeout, no caching.
Don't spool up a second request while the previous one is in progress.
If we repeatedly see the same receiver timestamp, warn the user that the JSON isn't being updated.
This commit is contained in:
Oliver Jowett 2015-01-07 18:43:08 +00:00
parent 97ca1c77e7
commit 93aedbe15c
2 changed files with 36 additions and 3 deletions

View file

@ -29,8 +29,22 @@ var TrackedHistorySize = 0;
var SitePosition = null;
var ReceiverClock = null;
var LastReceiverTimestamp = null;
var StaleReceiverCount = 0;
var FetchPending = null;
function fetchData() {
$.getJSON('data/aircraft.json', function(data) {
if (FetchPending !== null && FetchPending.state() == 'pending') {
// don't double up on fetches, let the last one resolve
return;
}
FetchPending = $.ajax({ url: 'data/aircraft.json',
timeout: 5000,
cache: false,
dataType: 'json' });
FetchPending.done(function(data) {
// Loop through all the planes in the data packet
var now = data.now;
var acs = data.aircraft;
@ -71,7 +85,25 @@ function fetchData() {
var rcv = new Date(now * 1000);
ReceiverClock.render(rcv.getUTCHours(),rcv.getUTCMinutes(),rcv.getUTCSeconds());
}
// Check for stale receiver data
if (LastReceiverTimestamp === now) {
StaleReceiverCount++;
if (StaleReceiverCount > 5) {
$("#update_error_detail").text("The data from dump1090 hasn't been updated in a while. Maybe dump1090 is no longer running?");
$("#update_error").css('display','block');
}
} else {
StaleReceiverCount = 0;
LastReceiverTimestamp = now;
$("#update_error").css('display','none');
}
});
FetchPending.fail(function(jqxhr, status, error) {
$("#update_error_detail").text("AJAX call failed (" + status + (error ? (": " + error) : "") + "). Maybe dump1090 is no longer running?");
$("#update_error").css('display','block');
});
}
function initialize() {

View file

@ -11,8 +11,9 @@ div#SpecialSquawkWarning { position: absolute; bottom: 25px; right: 430px; borde
background-color: #FFFFA3; opacity: 0.75; filter:alpha(opacity=75); padding: 5px;
text-align: center; }
table#optionsTabs { width: 100%; font-size: small; font-family: monospace; background-color: #ddd;
border: 1px; border-color: #000000;}
div#update_error { position: absolute; bottom: 25px; left: 25px; border: 2px solid red;
background-color: #FFFFA3; opacity: 0.75; filter:alpha(opacity=75); padding: 5px;
text-align: center; }
#tableinfo, #sudo_buttons { font-size: x-small; font-family: monospace; }