Updated blacklist and client api for ui error handling
parent
218fe9328c
commit
666573cd34
|
@ -82,11 +82,13 @@ public class BlacklistAPI {
|
||||||
catch (JsonSyntaxException e) {
|
catch (JsonSyntaxException e) {
|
||||||
logger.error("addNewBlacklistedSite failed due to JsonSyntaxException: " + e.getStackTrace().toString());
|
logger.error("addNewBlacklistedSite failed due to JsonSyntaxException: " + e.getStackTrace().toString());
|
||||||
m.put("code", HttpStatus.BAD_REQUEST);
|
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) {
|
} catch (IllegalStateException e) {
|
||||||
logger.error("addNewBlacklistedSite failed due to IllegalStateException: " + e.getStackTrace().toString());
|
logger.error("addNewBlacklistedSite failed due to IllegalStateException: " + e.getStackTrace().toString());
|
||||||
m.put("code", HttpStatus.BAD_REQUEST);
|
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";
|
return "jsonEntityView";
|
||||||
|
@ -112,11 +114,13 @@ public class BlacklistAPI {
|
||||||
catch (JsonSyntaxException e) {
|
catch (JsonSyntaxException e) {
|
||||||
logger.error("updateBlacklistedSite failed due to JsonSyntaxException: " + e.getStackTrace().toString());
|
logger.error("updateBlacklistedSite failed due to JsonSyntaxException: " + e.getStackTrace().toString());
|
||||||
m.put("code", HttpStatus.BAD_REQUEST);
|
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) {
|
} catch (IllegalStateException e) {
|
||||||
logger.error("updateBlacklistedSite failed due to IllegalStateException: " + e.getStackTrace().toString());
|
logger.error("updateBlacklistedSite failed due to IllegalStateException: " + e.getStackTrace().toString());
|
||||||
m.put("code", HttpStatus.BAD_REQUEST);
|
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) {
|
if (oldBlacklist == null) {
|
||||||
logger.error("updateBlacklistedSite failed; blacklist with id " + id + " could not be found");
|
logger.error("updateBlacklistedSite failed; blacklist with id " + id + " could not be found");
|
||||||
m.put("code", HttpStatus.NOT_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 {
|
} else {
|
||||||
|
|
||||||
BlacklistedSite newBlacklist = blacklistService.update(oldBlacklist, blacklist);
|
BlacklistedSite newBlacklist = blacklistService.update(oldBlacklist, blacklist);
|
||||||
|
@ -146,7 +151,8 @@ public class BlacklistAPI {
|
||||||
|
|
||||||
if (blacklist == null) {
|
if (blacklist == null) {
|
||||||
logger.error("deleteBlacklistedSite failed; blacklist with id " + id + " could not be found");
|
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 {
|
} else {
|
||||||
m.put("code", HttpStatus.OK);
|
m.put("code", HttpStatus.OK);
|
||||||
blacklistService.remove(blacklist);
|
blacklistService.remove(blacklist);
|
||||||
|
@ -164,7 +170,8 @@ public class BlacklistAPI {
|
||||||
if (blacklist == null) {
|
if (blacklist == null) {
|
||||||
logger.error("getBlacklistedSite failed; blacklist with id " + id + " could not be found");
|
logger.error("getBlacklistedSite failed; blacklist with id " + id + " could not be found");
|
||||||
m.put("code", HttpStatus.NOT_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 {
|
} else {
|
||||||
|
|
||||||
m.put("entity", blacklist);
|
m.put("entity", blacklist);
|
||||||
|
|
|
@ -138,11 +138,13 @@ public class ClientAPI {
|
||||||
catch (JsonSyntaxException e) {
|
catch (JsonSyntaxException e) {
|
||||||
logger.error("apiAddClient failed due to JsonSyntaxException: " + e.getStackTrace().toString());
|
logger.error("apiAddClient failed due to JsonSyntaxException: " + e.getStackTrace().toString());
|
||||||
m.addAttribute("code", HttpStatus.BAD_REQUEST);
|
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) {
|
} catch (IllegalStateException e) {
|
||||||
logger.error("apiAddClient failed due to IllegalStateException: " + e.getStackTrace().toString());
|
logger.error("apiAddClient failed due to IllegalStateException: " + e.getStackTrace().toString());
|
||||||
m.addAttribute("code", HttpStatus.BAD_REQUEST);
|
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
|
// if they leave the client secret empty, force it to be generated
|
||||||
|
@ -193,11 +195,13 @@ public class ClientAPI {
|
||||||
catch (JsonSyntaxException e) {
|
catch (JsonSyntaxException e) {
|
||||||
logger.error("apiUpdateClient failed due to JsonSyntaxException: " + e.getStackTrace().toString());
|
logger.error("apiUpdateClient failed due to JsonSyntaxException: " + e.getStackTrace().toString());
|
||||||
m.addAttribute("code", HttpStatus.BAD_REQUEST);
|
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) {
|
} catch (IllegalStateException e) {
|
||||||
logger.error("apiUpdateClient failed due to IllegalStateException: " + e.getStackTrace().toString());
|
logger.error("apiUpdateClient failed due to IllegalStateException: " + e.getStackTrace().toString());
|
||||||
m.addAttribute("code", HttpStatus.BAD_REQUEST);
|
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);
|
ClientDetailsEntity oldClient = clientService.getClientById(id);
|
||||||
|
@ -205,7 +209,8 @@ public class ClientAPI {
|
||||||
if (oldClient == null) {
|
if (oldClient == null) {
|
||||||
logger.error("apiUpdateClient failed; client with id " + id + " could not be found.");
|
logger.error("apiUpdateClient failed; client with id " + id + " could not be found.");
|
||||||
m.addAttribute("code", HttpStatus.NOT_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
|
// if they leave the client secret empty, force it to be generated
|
||||||
|
@ -247,6 +252,8 @@ public class ClientAPI {
|
||||||
if (client == null) {
|
if (client == null) {
|
||||||
logger.error("apiDeleteClient failed; client with id " + id + " could not be found.");
|
logger.error("apiDeleteClient failed; client with id " + id + " could not be found.");
|
||||||
modelAndView.getModelMap().put("code", HttpStatus.NOT_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 {
|
} else {
|
||||||
modelAndView.getModelMap().put("code", HttpStatus.OK);
|
modelAndView.getModelMap().put("code", HttpStatus.OK);
|
||||||
clientService.deleteClient(client);
|
clientService.deleteClient(client);
|
||||||
|
|
|
@ -32,7 +32,25 @@ var ListWidgetChildView = Backbone.View.extend({
|
||||||
"click .btn-delete":function (e) {
|
"click .btn-delete":function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
//this.$el.tooltip('delete');
|
//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);
|
_self.collection.add(item);
|
||||||
},
|
},
|
||||||
error:function(error, response) {
|
error:function(error, response) {
|
||||||
console.log("error: " + error);
|
//Pull out the response text.
|
||||||
console.log("response: " + response);
|
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
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -160,7 +160,22 @@ var ClientView = Backbone.View.extend({
|
||||||
app.clientListView.togglePlaceholder();
|
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();
|
app.clientListView.delegateEvents();
|
||||||
|
@ -483,9 +498,21 @@ var ClientFormView = Backbone.View.extend({
|
||||||
app.clientList.add(_self.model);
|
app.clientList.add(_self.model);
|
||||||
app.navigate('admin/clients', {trigger:true});
|
app.navigate('admin/clients', {trigger:true});
|
||||||
},
|
},
|
||||||
error:function (model,resp) {
|
error:function (error, response) {
|
||||||
console.error("Oops! The object didn't save correctly.",resp);
|
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;
|
return false;
|
||||||
|
|
Loading…
Reference in New Issue