Skip to content

Commit 544be58

Browse files
committed
Handle server errors better
Some basic error handling in the event the server is not giving us what we want.
1 parent 1c30862 commit 544be58

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

lnt/server/ui/static/lnt_tableau.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,26 @@
1818
"hash": tableau.dataTypeEnum.string,
1919
"code_size": tableau.dataTypeEnum.int};
2020

21+
/** Get a json payload from the LNT server asynchronously or error.
22+
* @param {string} payload_url JSON payloads URL.
23+
*/
2124
function getValue(payload_url) {
22-
var value = $.ajax({
25+
var response = $.ajax({
2326
url: payload_url,
24-
async: false
25-
}).responseText;
26-
return JSON.parse(value);
27+
async: false,
28+
cache: false,
29+
timeout: 60000, // Make all requests timeout after a minute.
30+
});
31+
32+
if (response.status >= 400) {
33+
var error_msg = "Requesting data from LNT failed with:\n\n HTTP " +
34+
response.status + ": " + response.responseText + "\n\nURL: " +
35+
payload_url
36+
tableau.abortWithError(error_msg);
37+
throw new Error(error_msg);
38+
}
39+
40+
return JSON.parse(response.responseText);
2741
}
2842

2943
function get_matching_machines(regexp) {

0 commit comments

Comments
 (0)