Skip to content

Commit 6206ea1

Browse files
author
Andreas Eisenkolb
committed
added a timeout for the proxy call
1 parent 872a362 commit 6206ea1

1 file changed

Lines changed: 32 additions & 17 deletions

File tree

Sidedbar.html

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -72,31 +72,46 @@
7272
// Insert Ajax loader icon
7373
$('<div id="ajax-loader-container"><img src="http://mics.fim.uni-passau.de/wp-content/uploads/2014/10/ajax-loader.gif" width="16px" height="16px" alt="ajax loader"/></div>').insertAfter("#eexcess-recommendations-list");
7474

75+
var responded = false;
76+
var timeout = false;
77+
78+
setTimeout(function() {
79+
if(!responded) {
80+
timeout = true;
81+
removeAjaxLoader();
82+
showError("The server timed out waiting for the request.", $('#button-bar'));
83+
$('#get-recommendations').removeAttr("disabled");
84+
}
85+
}, 20000);
86+
7587
google.script.run
7688
.withSuccessHandler(
7789
function(recommendations, element) {
78-
79-
removeAjaxLoader();
80-
var container = $("#eexcess-recommendations-list");
81-
// Parsing the JSON string
82-
var o = JSON.parse(recommendations);
90+
if(!timeout) {
91+
responded = true;
92+
removeAjaxLoader();
93+
var container = $("#eexcess-recommendations-list");
94+
// Parsing the JSON string
95+
var o = JSON.parse(recommendations);
8396

84-
if(o.totalResults > 0) {
85-
// iterate the results and append the list elements
86-
$.each(o.result, function() {
87-
container.append("<li><a href='" + this.uri + "' target='_blank'>" + this.title + "</a></li>");
88-
})
89-
} else {
90-
showError("No results found", $('#button-bar'));
97+
if(o.totalResults > 0) {
98+
// iterate the results and append the list elements
99+
$.each(o.result, function() {
100+
container.append("<li><a href='" + this.uri + "' target='_blank'>" + this.title + "</a></li>");
101+
})
102+
} else {
103+
showError("No results found", $('#button-bar'));
104+
}
105+
element.disabled = false;
91106
}
92-
93-
element.disabled = false;
94107
})
95108
.withFailureHandler(
96109
function(msg, element) {
97-
removeAjaxLoader();
98-
showError(msg, $('#button-bar'));
99-
element.disabled = false;
110+
if(!timeout) {
111+
removeAjaxLoader();
112+
showError(msg, $('#button-bar'));
113+
element.disabled = false;
114+
}
100115
})
101116
.withUserObject(this)
102117
.getRecommendations();

0 commit comments

Comments
 (0)