Updated whitelist api for ui error handling

pull/306/merge
Amanda Anganes 2013-03-28 12:43:47 -04:00
parent 666573cd34
commit 5b321b9c86
2 changed files with 41 additions and 8 deletions

View File

@ -78,11 +78,13 @@ public class WhitelistAPI {
} catch (JsonParseException e) {
logger.error("addNewWhitelistedSite failed due to JsonParseException: " + e.getStackTrace().toString());
m.addAttribute("code", HttpStatus.BAD_REQUEST);
return "httpCodeView";
m.addAttribute("entity", "An error occurred while processing your request. Contact a system administrator for assistance.");
return "jsonEntityView";
} catch (IllegalStateException e) {
logger.error("addNewWhitelistedSite failed due to IllegalStateException: " + e.getStackTrace().toString());
m.addAttribute("code", HttpStatus.BAD_REQUEST);
return "httpCodeView";
m.addAttribute("entity", "An error occurred while processing your request. Contact a system administrator for assistance.");
return "jsonEntityView";
}
// save the id of the person who created this
@ -113,11 +115,13 @@ public class WhitelistAPI {
} catch (JsonParseException e) {
logger.error("updateWhitelistedSite failed due to JsonParseException: " + e.getStackTrace().toString());
m.put("code", HttpStatus.BAD_REQUEST);
return "httpCodeView";
m.put("entity", "An error occurred while processing your request. Contact a system administrator for assistance.");
return "jsonEntityView";
} catch (IllegalStateException e) {
logger.error("updateWhitelistedSite failed due to IllegalStateException: " + e.getStackTrace().toString());
m.put("code", HttpStatus.BAD_REQUEST);
return "httpCodeView";
m.put("entity", "An error occurred while processing your request. Contact a system administrator for assistance.");
return "jsonEntityView";
}
WhitelistedSite oldWhitelist = whitelistService.getById(id);
@ -148,6 +152,8 @@ public class WhitelistAPI {
if (whitelist == null) {
logger.error("deleteWhitelistedSite failed; whitelist with id " + id + " could not be found.");
m.put("code", HttpStatus.NOT_FOUND);
m.put("entity", "An error occurred while processing your request. The requested whitelist entry could not be found.");
return "jsonEntityView";
} else {
m.put("code", HttpStatus.OK);
whitelistService.remove(whitelist);

View File

@ -129,7 +129,22 @@ var WhiteListView = Backbone.View.extend({
app.whiteListListView.togglePlaceholder();
});
});
}
},
error:function (error, response) {
console.log("An error occurred when deleting a whitelist entry");
//Pull out the response text.
var responseText = JSON.parse(response.responseText);
//Display an alert with an error message
$('#modalAlert div.modal-body').html("<div class='alert alert-error'><strong>Warning!</strong>" + responseText + "</div>");
$("#modalAlert").modal({ // wire up the actual modal functionality and show the dialog
"backdrop" : "static",
"keyboard" : true,
"show" : true // ensure the modal is shown immediately
});
}
});
app.whiteListListView.delegateEvents();
@ -182,9 +197,21 @@ var WhiteListFormView = Backbone.View.extend({
app.whiteListList.add(_self.model);
app.navigate('admin/whitelists', {trigger:true});
},
error:function (model,resp) {
console.error("Oops! The object didn't save correctly.",resp);
}
error:function (error, response) {
console.log("An error occurred when deleting from a list widget");
//Pull out the response text.
var responseText = JSON.parse(response.responseText);
//Display an alert with an error message
$('#modalAlert div.modal-body').html("<div class='alert alert-error'><strong>Warning!</strong>" + responseText + "</div>");
$("#modalAlert").modal({ // wire up the actual modal functionality and show the dialog
"backdrop" : "static",
"keyboard" : true,
"show" : true // ensure the modal is shown immediately
});
}
});
}