Commit c2505cf5 authored by Leigh B Stoller's avatar Leigh B Stoller

Catch network errors in CallServerMethod() and convert to our standard

json error format so that users get better feedback when there is a
network failure.
parent 59eed578
......@@ -154,10 +154,15 @@ APT_OPTIONS.CallServerMethod = function (url, route, method, args, callback)
url = 'https://' + window.location.host + '/apt/server-ajax.php';
url = 'server-ajax.php';
var networkError = {
"code" : -1,
"value" : "Server error, possible network failure. Try again later.",
};
if (args == null) {
args = {"noargs" : "noargs"};
}
return $.ajax({
var jqxhr = $.ajax({
// the URL for the request
url: url,
success: function (json) {
......@@ -166,6 +171,11 @@ APT_OPTIONS.CallServerMethod = function (url, route, method, args, callback)
callback(json);
}
},
error: function (jqXHR, textStatus, errorThrown) {
if (callback !== undefined) {
callback(networkError);
}
},
// the data to send (will be converted to a query string)
data: {
......@@ -180,6 +190,16 @@ APT_OPTIONS.CallServerMethod = function (url, route, method, args, callback)
// the type of data we expect back
dataType : "json",
});
var defer = $.Deferred();
jqxhr.done(function (data) {
defer.resolve(data);
});
jqxhr.fail(function (jqXHR, textStatus, errorThrown) {
networkError["jqXHR"] = jqXHR;
defer.resolve(networkError);
});
return defer;
};
window.APT_OPTIONS.announceDismiss = function (aid) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment