handle errors other than timedout in refresh
Ted Unangst tedu@tedunangst.com
Wed, 31 Jan 2024 13:43:43 -0500
1 files changed,
8 insertions(+),
7 deletions(-)
jump to
M
views/honkpage.js
→
views/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("")