From 55f3d8c1d099186aafc2f4e20c623dbcde25173b Mon Sep 17 00:00:00 2001 From: Stan Silvert Date: Thu, 4 May 2017 15:21:05 -0400 Subject: [PATCH] KEYCLOAK-4462: Use errorInterceptor instead of handling errors locally --- .../theme/base/admin/resources/js/app.js | 2 + .../admin/resources/js/controllers/clients.js | 17 ------- .../admin/resources/js/controllers/realm.js | 16 ------- .../admin/resources/js/controllers/users.js | 48 ------------------- 4 files changed, 2 insertions(+), 81 deletions(-) diff --git a/themes/src/main/resources/theme/base/admin/resources/js/app.js b/themes/src/main/resources/theme/base/admin/resources/js/app.js index 3052ae9566..ac14c723f8 100755 --- a/themes/src/main/resources/theme/base/admin/resources/js/app.js +++ b/themes/src/main/resources/theme/base/admin/resources/js/app.js @@ -1948,6 +1948,8 @@ module.factory('errorInterceptor', function($q, $window, $rootScope, $location, } else { Notifications.error("An unexpected server error has occurred"); } + } else { + Notifications.error("No response from server."); } return $q.reject(response); } diff --git a/themes/src/main/resources/theme/base/admin/resources/js/controllers/clients.js b/themes/src/main/resources/theme/base/admin/resources/js/controllers/clients.js index a6b0ac1aef..315b8a53cb 100755 --- a/themes/src/main/resources/theme/base/admin/resources/js/controllers/clients.js +++ b/themes/src/main/resources/theme/base/admin/resources/js/controllers/clients.js @@ -437,9 +437,6 @@ module.controller('ClientCertificateImportCtrl', function($scope, $location, $ht }).success(function(data, status, headers) { Notifications.success("Keystore uploaded successfully."); $location.url(redirectLocation); - }).error(function(data) { - var errorMsg = data['error_description'] ? data['error_description'] : 'The key store can not be uploaded. Please verify the file.'; - Notifications.error(errorMsg); }); //.then(success, error, progress); } @@ -1806,12 +1803,6 @@ module.controller('ClientProtocolMapperCtrl', function($scope, realm, serverInfo mapper = angular.copy($scope.mapper); $location.url("/realms/" + realm.realm + '/clients/' + client.id + "/mappers/" + $scope.model.mapper.id); Notifications.success("Your changes have been saved."); - }, function(error) { - if (error.status == 400 && error.data.error_description) { - Notifications.error(error.data.error_description); - } else { - Notifications.error('Unexpected error when updating protocol mapper'); - } }); }; @@ -1878,14 +1869,6 @@ module.controller('ClientProtocolMapperCreateCtrl', function($scope, realm, serv var id = l.substring(l.lastIndexOf("/") + 1); $location.url("/realms/" + realm.realm + '/clients/' + client.id + "/mappers/" + id); Notifications.success("Mapper has been created."); - }, function(error) { - if (error.status == 400 && error.data.error_description) { - Notifications.error(error.data.error_description); - } else if (error.status == 409 && error.data.errorMessage) { - Notifications.error(error.data.errorMessage); - } else { - Notifications.error('Unexpected error when updating protocol mapper'); - } }); }; diff --git a/themes/src/main/resources/theme/base/admin/resources/js/controllers/realm.js b/themes/src/main/resources/theme/base/admin/resources/js/controllers/realm.js index bcb0d0c211..bcc655fbcc 100644 --- a/themes/src/main/resources/theme/base/admin/resources/js/controllers/realm.js +++ b/themes/src/main/resources/theme/base/admin/resources/js/controllers/realm.js @@ -1220,10 +1220,6 @@ module.controller('GenericKeystoreCtrl', function($scope, $location, Notificatio $location.url("/realms/" + realm.realm + "/keys/providers/" + $scope.instance.providerId + "/" + id); Notifications.success("The provider has been created."); - }, function (errorResponse) { - if (errorResponse.data && errorResponse.data['error_description']) { - Notifications.error(errorResponse.data['error_description']); - } }); } else { Components.update({realm: realm.realm, @@ -1232,10 +1228,6 @@ module.controller('GenericKeystoreCtrl', function($scope, $location, Notificatio $scope.instance, function () { $route.reload(); Notifications.success("The provider has been updated."); - }, function (errorResponse) { - if (errorResponse.data && errorResponse.data['error_description']) { - Notifications.error(errorResponse.data['error_description']); - } }); } }; @@ -2463,10 +2455,6 @@ module.controller('ClientRegPolicyDetailCtrl', function($scope, realm, clientReg var id = l.substring(l.lastIndexOf("/") + 1); $location.url("/realms/" + realm.realm + "/client-registration/client-reg-policies/" + $scope.instance.providerId + "/" + id); Notifications.success("The policy has been created."); - }, function (errorResponse) { - if (errorResponse.data && errorResponse.data['error_description']) { - Notifications.error(errorResponse.data['error_description']); - } }); } else { Components.update({realm: realm.realm, @@ -2475,10 +2463,6 @@ module.controller('ClientRegPolicyDetailCtrl', function($scope, realm, clientReg $scope.instance, function () { $route.reload(); Notifications.success("The policy has been updated."); - }, function (errorResponse) { - if (errorResponse.data && errorResponse.data['error_description']) { - Notifications.error(errorResponse.data['error_description']); - } }); } }; diff --git a/themes/src/main/resources/theme/base/admin/resources/js/controllers/users.js b/themes/src/main/resources/theme/base/admin/resources/js/controllers/users.js index 8f426189f2..13d83436b7 100755 --- a/themes/src/main/resources/theme/base/admin/resources/js/controllers/users.js +++ b/themes/src/main/resources/theme/base/admin/resources/js/controllers/users.js @@ -59,12 +59,6 @@ module.controller('UserRoleMappingCtrl', function($scope, $http, realm, user, cl $scope.selectedClientMappings = []; } Notifications.success("Role mappings updated."); - }).error(function(response) { - if (response && response['error_description']) { - Notifications.error(response['error_description']); - } else { - Notifications.error("Failed to remove role mapping"); - } }); }; @@ -93,12 +87,6 @@ module.controller('UserRoleMappingCtrl', function($scope, $http, realm, user, cl $scope.realmComposite = CompositeRealmRoleMapping.query({realm : realm.realm, userId : user.id}); $scope.realmRoles = AvailableRealmRoleMapping.query({realm : realm.realm, userId : user.id}); Notifications.success("Role mappings updated."); - }).error(function(response) { - if (response && response['error_description']) { - Notifications.error(response['error_description']); - } else { - Notifications.error("Failed to remove role mapping"); - } }); }; @@ -537,12 +525,6 @@ module.controller('UserCredentialsCtrl', function($scope, realm, user, $route, R Notifications.success("The password has been reset"); $scope.password = null; $scope.confirmPassword = null; - }, function(response) { - if (response.data && response.data['error_description']) { - Notifications.error(response.data['error_description']); - } else { - Notifications.error("Failed to reset user password"); - } }); }, function() { $scope.password = null; @@ -822,10 +804,6 @@ module.controller('GenericUserStorageCtrl', function($scope, $location, Notifica $location.url("/realms/" + realm.realm + "/user-storage/providers/" + $scope.instance.providerId + "/" + id); Notifications.success("The provider has been created."); - }, function (errorResponse) { - if (errorResponse.data && errorResponse.data['error_description']) { - Notifications.error(errorResponse.data['error_description']); - } }); } else { console.log('update existing provider'); @@ -835,10 +813,6 @@ module.controller('GenericUserStorageCtrl', function($scope, $location, Notifica $scope.instance, function () { $route.reload(); Notifications.success("The provider has been updated."); - }, function (errorResponse) { - if (errorResponse.data && errorResponse.data['error_description']) { - Notifications.error(errorResponse.data['error_description']); - } }); } }; @@ -950,12 +924,6 @@ module.controller('UserGroupMembershipCtrl', function($scope, $route, realm, gro UserGroupMapping.remove({realm: realm.realm, userId: user.id, groupId: $scope.selectedGroup.id}, function() { Notifications.success('Removed group membership'); $route.reload(); - }, function(response) { - if (response.data && response.data['error_description']) { - Notifications.error(response.data['error_description']); - } else { - Notifications.error("Failed to leave group"); - } }); }; @@ -1231,10 +1199,6 @@ module.controller('LDAPUserStorageCtrl', function($scope, $location, Notificatio $location.url("/realms/" + realm.realm + "/user-storage/providers/" + $scope.instance.providerId + "/" + id); Notifications.success("The provider has been created."); - }, function (errorResponse) { - if (errorResponse.data && errorResponse.data['error_description']) { - Notifications.error(errorResponse.data['error_description']); - } }); } else { Components.update({realm: realm.realm, @@ -1243,10 +1207,6 @@ module.controller('LDAPUserStorageCtrl', function($scope, $location, Notificatio $scope.instance, function () { $route.reload(); Notifications.success("The provider has been updated."); - }, function (errorResponse) { - if (errorResponse.data && errorResponse.data['error_description']) { - Notifications.error(errorResponse.data['error_description']); - } }); } }; @@ -1409,10 +1369,6 @@ module.controller('LDAPMapperCtrl', function($scope, $route, realm, provider, m $scope.mapper, function () { $route.reload(); Notifications.success("The mapper has been updated."); - }, function (errorResponse) { - if (errorResponse.data && errorResponse.data['error_description']) { - Notifications.error(errorResponse.data['error_description']); - } }); }; @@ -1498,10 +1454,6 @@ module.controller('LDAPMapperCreateCtrl', function($scope, realm, provider, mapp $location.url("/realms/" + realm.realm + "/ldap-mappers/" + $scope.mapper.parentId + "/mappers/" + id); Notifications.success("The mapper has been created."); - }, function (errorResponse) { - if (errorResponse.data && errorResponse.data['error_description']) { - Notifications.error(errorResponse.data['error_description']); - } }); };