From a84e09c70fcc02d70777b3e627f88563fc5689fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gr=C3=B6ber?= Date: Mon, 6 Aug 2018 17:32:54 +0200 Subject: [PATCH] Add error handling to status.txt request --- common/body_tag.html | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/common/body_tag.html b/common/body_tag.html index dce75a4..f153a41 100644 --- a/common/body_tag.html +++ b/common/body_tag.html @@ -46,24 +46,27 @@ var its = (function() { } function refresh() { - $.get('https://it-syndikat.org/api/status.txt') - .done(function(data) { - var a = data.split(','); - var isitopen = a[0]; - var up_date = new Date(parseInt(a[1]) * 1000); + $.get('https://it-syndikat.org/api/status.txt') + .then(function(data) { + var a = data.split(','); + var isitopen = a[0]; + var up_date = new Date(parseInt(a[1]) * 1000); - var state; + var state; - if(isitopen === 'true') - state = 'open'; - else if(isitopen === 'false') - state = 'closed'; - else - state = 'error'; + if(isitopen === 'true') + state = 'open'; + else if(isitopen === 'false') + state = 'closed'; + else + state = 'error'; - console.log('isitopen: it is', state); - update_dom(state); - }); + console.log('isitopen: it is', state); + update_dom(state); + }, function() { + console.log('isitopen: it is', 'error'); + update_dom('error'); + }); } function update_dom(state) {