handle errors and timeouts when doing the jaxy
This commit is contained in:
parent
29c9afb6fc
commit
d8c27d7ba8
|
@ -9,14 +9,19 @@ function encode(hash) {
|
||||||
function post(url, data) {
|
function post(url, data) {
|
||||||
var x = new XMLHttpRequest()
|
var x = new XMLHttpRequest()
|
||||||
x.open("POST", url)
|
x.open("POST", url)
|
||||||
|
x.timeout = 30 * 1000
|
||||||
x.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
|
x.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
|
||||||
x.send(data)
|
x.send(data)
|
||||||
}
|
}
|
||||||
function get(url, whendone) {
|
function get(url, whendone, whentimedout) {
|
||||||
var x = new XMLHttpRequest()
|
var x = new XMLHttpRequest()
|
||||||
x.open("GET", url)
|
x.open("GET", url)
|
||||||
|
x.timeout = 5 * 1000
|
||||||
x.responseType = "json"
|
x.responseType = "json"
|
||||||
x.onload = function() { whendone(x) }
|
x.onload = function() { whendone(x) }
|
||||||
|
if (whentimedout) {
|
||||||
|
x.ontimeout = function(e) { whentimedout(x, e) }
|
||||||
|
}
|
||||||
x.send()
|
x.send()
|
||||||
}
|
}
|
||||||
function bonk(el, xid) {
|
function bonk(el, xid) {
|
||||||
|
@ -160,10 +165,18 @@ function refreshhonks(btn) {
|
||||||
var stash = curpagestate.name + ":" + curpagestate.arg
|
var stash = curpagestate.name + ":" + curpagestate.arg
|
||||||
args["tophid"] = tophid[stash]
|
args["tophid"] = tophid[stash]
|
||||||
get("/hydra?" + encode(args), function(xhr) {
|
get("/hydra?" + encode(args), function(xhr) {
|
||||||
var lenhonks = fillinhonks(xhr, true)
|
|
||||||
btn.innerHTML = "refresh"
|
btn.innerHTML = "refresh"
|
||||||
btn.disabled = false
|
btn.disabled = false
|
||||||
|
if (xhr.status == 200) {
|
||||||
|
var lenhonks = fillinhonks(xhr, true)
|
||||||
refreshupdate(" " + lenhonks + " new")
|
refreshupdate(" " + lenhonks + " new")
|
||||||
|
} else {
|
||||||
|
refreshupdate(" status: " + xhr.status)
|
||||||
|
}
|
||||||
|
}, function(xhr, e) {
|
||||||
|
btn.innerHTML = "refresh"
|
||||||
|
btn.disabled = false
|
||||||
|
refreshupdate(" timed out")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
function statechanger(evt) {
|
function statechanger(evt) {
|
||||||
|
@ -203,7 +216,15 @@ function switchtopage(name, arg) {
|
||||||
// or create one and fill it
|
// or create one and fill it
|
||||||
honksonpage.prepend(document.createElement("div"))
|
honksonpage.prepend(document.createElement("div"))
|
||||||
var args = hydrargs()
|
var args = hydrargs()
|
||||||
get("/hydra?" + encode(args), function(xhr) { fillinhonks(xhr, false) })
|
get("/hydra?" + encode(args), function(xhr) {
|
||||||
|
if (xhr.status == 200) {
|
||||||
|
var lenhonks = fillinhonks(xhr, false)
|
||||||
|
} else {
|
||||||
|
refreshupdate(" status: " + xhr.status)
|
||||||
|
}
|
||||||
|
}, function(xhr, e) {
|
||||||
|
refreshupdate(" timed out")
|
||||||
|
})
|
||||||
}
|
}
|
||||||
refreshupdate("")
|
refreshupdate("")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue