From 5b321b9c86dcd4f032c3fec436959e1419592daf Mon Sep 17 00:00:00 2001 From: Amanda Anganes Date: Thu, 28 Mar 2013 12:43:47 -0400 Subject: [PATCH] Updated whitelist api for ui error handling --- .../openid/connect/web/WhitelistAPI.java | 14 +++++--- .../src/main/webapp/resources/js/whitelist.js | 35 ++++++++++++++++--- 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/openid-connect-server/src/main/java/org/mitre/openid/connect/web/WhitelistAPI.java b/openid-connect-server/src/main/java/org/mitre/openid/connect/web/WhitelistAPI.java index 4a72e4e73..a9910ca17 100644 --- a/openid-connect-server/src/main/java/org/mitre/openid/connect/web/WhitelistAPI.java +++ b/openid-connect-server/src/main/java/org/mitre/openid/connect/web/WhitelistAPI.java @@ -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); diff --git a/openid-connect-server/src/main/webapp/resources/js/whitelist.js b/openid-connect-server/src/main/webapp/resources/js/whitelist.js index e25c1ecfb..0e5daf567 100644 --- a/openid-connect-server/src/main/webapp/resources/js/whitelist.js +++ b/openid-connect-server/src/main/webapp/resources/js/whitelist.js @@ -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("
Warning!" + responseText + "
"); + + $("#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("
Warning!" + responseText + "
"); + + $("#modalAlert").modal({ // wire up the actual modal functionality and show the dialog + "backdrop" : "static", + "keyboard" : true, + "show" : true // ensure the modal is shown immediately + }); + } }); }