all repos — honk @ 466fa4b6ec5157da77e04afcce29e06097509dc6

my fork of honk

handle errors other than timedout in refresh
Ted Unangst tedu@tedunangst.com
Wed, 31 Jan 2024 13:43:43 -0500
commit

466fa4b6ec5157da77e04afcce29e06097509dc6

parent

5f1f1df8966b4475bb7e95b04ea5fd0ee6b9d441

1 files changed, 8 insertions(+), 7 deletions(-)

jump to
M views/honkpage.jsviews/honkpage.js

@@ -19,14 +19,15 @@ x.timeout = 30 * 1000

x.setRequestHeader("Content-Type", "application/x-www-form-urlencoded") x.send(data) } -function get(url, whendone, whentimedout) { +function get(url, whendone, errfunction) { var x = new XMLHttpRequest() x.open("GET", url) x.timeout = 15 * 1000 x.responseType = "json" x.onload = function() { whendone(x) } - if (whentimedout) { - x.ontimeout = function(e) { whentimedout(x, e) } + if (errfunction) { + x.ontimeout = function(e) { errfunction(" timed out") } + x.onerror = function(e) { errfunction(" error") } } x.send() }

@@ -180,10 +181,10 @@ refreshupdate(" " + lenhonks + " new")

} else { refreshupdate(" status: " + xhr.status) } - }, function(xhr, e) { + }, function(err) { btn.innerHTML = "refresh" btn.disabled = false - refreshupdate(" timed out") + refreshupdate(err) }) } function statechanger(evt) {

@@ -229,8 +230,8 @@ fillinhonks(xhr, false)

} else { refreshupdate(" status: " + xhr.status) } - }, function(xhr, e) { - refreshupdate(" timed out") + }, function(err) { + refreshupdate(err) }) } refreshupdate("")