Add error handling to status.txt request

This commit is contained in:
Daniel Gröber 2018-08-06 17:32:54 +02:00
parent 33e53cda3d
commit a84e09c70f

View file

@ -46,24 +46,27 @@ var its = (function() {
} }
function refresh() { function refresh() {
$.get('https://it-syndikat.org/api/status.txt') $.get('https://it-syndikat.org/api/status.txt')
.done(function(data) { .then(function(data) {
var a = data.split(','); var a = data.split(',');
var isitopen = a[0]; var isitopen = a[0];
var up_date = new Date(parseInt(a[1]) * 1000); var up_date = new Date(parseInt(a[1]) * 1000);
var state; var state;
if(isitopen === 'true') if(isitopen === 'true')
state = 'open'; state = 'open';
else if(isitopen === 'false') else if(isitopen === 'false')
state = 'closed'; state = 'closed';
else else
state = 'error'; state = 'error';
console.log('isitopen: it is', state); console.log('isitopen: it is', state);
update_dom(state); update_dom(state);
}); }, function() {
console.log('isitopen: it is', 'error');
update_dom('error');
});
} }
function update_dom(state) { function update_dom(state) {