Skip to content

Commit

Permalink
Merge pull request #326 from andig/network-error
Browse files Browse the repository at this point in the history
Better network error messages
  • Loading branch information
andig committed Jun 23, 2015
2 parents 2b59b44 + ea1052f commit da51339
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
21 changes: 15 additions & 6 deletions htdocs/frontend/javascripts/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ vz.getPermalink = function() {
vz.load = function(args) {
$.extend(args, {
accepts: 'application/json',
beforeSend: function (xhr, settings) {
// remember URL for potential error messages
xhr.requestUrl = settings.url;
},
beforeSend: function (xhr, settings) {
// remember URL for potential error messages
xhr.requestUrl = settings.url;
},
error: function(xhr) {
try {
var msg;
Expand All @@ -112,11 +112,20 @@ vz.load = function(args) {
}
}
else {
msg = xhr.requestUrl + ':<br/><br/>Unknown middleware response';
msg = "<a href='" + xhr.requestUrl + "' style='text-decoration:none'>" + xhr.requestUrl + "</a>";
if (xhr.responseText) {
msg += '<br/><br/>' + $(xhr.responseText).text().substring(0,300);
}
throw new Exception(xhr.statusText, msg, xhr.status);

var title = "Network Error";
if (xhr.status > 0) {
title += " (" + xhr.status + " " + xhr.statusText + ")";
}
else if (xhr.statusText !== "") {
title += " (" + xhr.statusText + ")";
}

throw new Exception(title, msg);
}
}
catch (e) {
Expand Down
11 changes: 8 additions & 3 deletions htdocs/frontend/javascripts/wui.js
Original file line number Diff line number Diff line change
Expand Up @@ -834,22 +834,27 @@ vz.wui.dialogs.error = function(error, description, code) {
error = code + ': ' + error;
}

$('<div>')
.append($('<span>').html(description))
.dialog({
// make error messages singleton (suppress follow-on errors)
vz.wui.errorDialog = true;

$('<div>').append(
$('<span>').html(description)
).dialog({
title: error,
width: 450,
dialogClass: 'ui-error',
resizable: false,
modal: true,
buttons: {
Ok: function() {
vz.wui.errorDialog = false;
$(this).dialog('close');
}
}
});
};

vz.wui.dialogs.exception = function(exception) {
if (vz.wui.errorDialog) return;
this.error(exception.type, exception.message, exception.code);
};

0 comments on commit da51339

Please sign in to comment.