add explicit timeout logic for updates so that GUI doesn't have to be refreshed when the API takes more than 20s to respond.
diff --git a/web/ons-demo/js/model.js b/web/ons-demo/js/model.js
index 5026bd4..f251c87 100644
--- a/web/ons-demo/js/model.js
+++ b/web/ons-demo/js/model.js
@@ -91,17 +91,29 @@
urls = proxyURLs;
}
+var timeoutMS = 20000;
+
function makeRequest(key) {
var url = urls[key];
if (url) {
return function (cb) {
- d3.json(url, function (error, result) {
+ var timeout;
+ var xhr = d3.json(url, function (error, result) {
+ clearTimeout(timeout);
+
if (error) {
error = url + ' : ' + error.status;
}
- cb(error, result);
+ if (cb) {
+ cb(error, result);
+ }
});
+ timeout = setTimeout(function () {
+ xhr.abort();
+ cb(url + ' timed out after ' + timeoutMS + ' ms');
+ cb = null;
+ }, timeoutMS);
}
} else {
return function (cb) {