Set timeout for urb.req

This sets a 1 minute timout on the urb.req xhr object. If no response
is received after one minute, it passes an error to the callback with a
408 status code.

I've also made sure that a 'beat' response resets the dely property back
to 250, instead of maintaining the previous value.

Fixes urbit/talk#21
This commit is contained in:
Matt Steedman 2016-06-14 23:30:28 -04:00 committed by Raymond Pasco
parent 2a10b2c7ce
commit 769a62f3a9

View File

@ -28,6 +28,8 @@ window.urb.req = function(method,url,params,json,cb) {
if(json)
xhr.setRequestHeader("content-type", "text/json")
xhr.timeout = 60000
if(!window.urb.oryx) throw "No CSRF token" // XX fetch auth.json
_data = {oryx: window.urb.oryx}
if(params.xyro) { _data.xyro = params.xyro; }
@ -59,6 +61,12 @@ window.urb.req = function(method,url,params,json,cb) {
cb(err,res)
}
}
xhr.ontimeout = function() {
cb({
status:408,
data:null
})
}
xhr.onerror = function() {
cb({
status:this.status,
@ -165,8 +173,10 @@ window.urb.poll = function(params) {
this.req("get",url,params,true,function(err,res) {
$this.poll.dely = params.dely || $this.poll.dely
if(res){
if(res.data.beat)
if(res.data.beat) {
$this.poll.dely = params.dely || 250
return $this.poll(params)
}
switch(res.data.type){
case "news":
return document.location.reload() // XX check autoreload