Updated blacklist and client api for ui error handling

pull/306/merge
Amanda Anganes 2013-03-28 12:37:18 -04:00
parent 218fe9328c
commit 666573cd34
4 changed files with 87 additions and 19 deletions

View File

@ -82,11 +82,13 @@ public class BlacklistAPI {
catch (JsonSyntaxException e) {
logger.error("addNewBlacklistedSite failed due to JsonSyntaxException: " + 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("addNewBlacklistedSite 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. Refresh and try again - if the problem persists, contact a system administrator for assistance.");
return "jsonEntityView";
}
return "jsonEntityView";
@ -112,11 +114,13 @@ public class BlacklistAPI {
catch (JsonSyntaxException e) {
logger.error("updateBlacklistedSite failed due to JsonSyntaxException: " + 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("updateBlacklistedSite 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. Refresh and try again - if the problem persists, contact a system administrator for assistance.");
return "jsonEntityView";
}
@ -125,7 +129,8 @@ public class BlacklistAPI {
if (oldBlacklist == null) {
logger.error("updateBlacklistedSite failed; blacklist with id " + id + " could not be found");
m.put("code", HttpStatus.NOT_FOUND);
return "httpCodeView";
m.put("entity", "An error occurred while processing your request - the requested blacklisted site could not be found.");
return "jsonEntityView";
} else {
BlacklistedSite newBlacklist = blacklistService.update(oldBlacklist, blacklist);
@ -146,7 +151,8 @@ public class BlacklistAPI {
if (blacklist == null) {
logger.error("deleteBlacklistedSite failed; blacklist 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 blacklisted site could not be found.");
return "jsonEntityView";
} else {
m.put("code", HttpStatus.OK);
blacklistService.remove(blacklist);
@ -164,7 +170,8 @@ public class BlacklistAPI {
if (blacklist == null) {
logger.error("getBlacklistedSite failed; blacklist with id " + id + " could not be found");
m.put("code", HttpStatus.NOT_FOUND);
return "httpCodeView";
m.put("entity", "An error occurred while processing your request - the requested blacklisted site could not be found.");
return "jsonEntityView";
} else {
m.put("entity", blacklist);

View File

@ -138,11 +138,13 @@ public class ClientAPI {
catch (JsonSyntaxException e) {
logger.error("apiAddClient failed due to JsonSyntaxException: " + 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("apiAddClient 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";
}
// if they leave the client secret empty, force it to be generated
@ -193,11 +195,13 @@ public class ClientAPI {
catch (JsonSyntaxException e) {
logger.error("apiUpdateClient failed due to JsonSyntaxException: " + 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("apiUpdateClient 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";
}
ClientDetailsEntity oldClient = clientService.getClientById(id);
@ -205,7 +209,8 @@ public class ClientAPI {
if (oldClient == null) {
logger.error("apiUpdateClient failed; client with id " + id + " could not be found.");
m.addAttribute("code", HttpStatus.NOT_FOUND);
return "httpCodeView";
m.addAttribute("entity", "An error occurred while processing your request. The requested client could not be found.");
return "jsonEntityView";
}
// if they leave the client secret empty, force it to be generated
@ -247,6 +252,8 @@ public class ClientAPI {
if (client == null) {
logger.error("apiDeleteClient failed; client with id " + id + " could not be found.");
modelAndView.getModelMap().put("code", HttpStatus.NOT_FOUND);
modelAndView.getModelMap().put("entity", "An error occurred while processing your request. The requested client could not be found.");
return "jsonEntityView";
} else {
modelAndView.getModelMap().put("code", HttpStatus.OK);
clientService.deleteClient(client);

View File

@ -32,7 +32,25 @@ var ListWidgetChildView = Backbone.View.extend({
"click .btn-delete":function (e) {
e.preventDefault();
//this.$el.tooltip('delete');
this.model.destroy();
this.model.destroy({
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
});
}
});
}
},
@ -252,8 +270,17 @@ var BlackListWidgetView = ListWidgetView.extend({
_self.collection.add(item);
},
error:function(error, response) {
console.log("error: " + error);
console.log("response: " + response);
//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
});
}
});

View File

@ -160,7 +160,22 @@ var ClientView = Backbone.View.extend({
app.clientListView.togglePlaceholder();
});
});
}
},
error:function (error, response) {
console.log("An error occurred when deleting a client");
//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.clientListView.delegateEvents();
@ -483,9 +498,21 @@ var ClientFormView = Backbone.View.extend({
app.clientList.add(_self.model);
app.navigate('admin/clients', {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
});
}
});
return false;