okfn/recline — Issue #30: Wrap any JSONP requests in timeouts to catch errors
Author: rgrp
Created: 2012-01-26 09:19:38+00:00
State: open

At the moment jsonp requests in Backends don't raise errors (because of nature of JSONP). We may wish to wrap in timeouts as a crude way to catch these

var timeout = 10000;
var timer = setTimeout(function error() {
callback({
error: {
title: 'Request Error',
message: 'Had timeout with Backend (probably error) ' + (timeout / 1000) + ' seconds'
}
});
}, timeout);

// later
$.ajax({
url: url,
dataType: 'jsonp',
success: function(data) {
clearTimeout(timer);
callback(data);
}
});