From d068fef76781f55d6b9ac951687e865e474e3a5b Mon Sep 17 00:00:00 2001 From: Jake McDermott Date: Fri, 16 Aug 2019 10:17:43 -0400 Subject: [PATCH] handle message validation errors --- .../client/src/notifications/add/add.controller.js | 12 ++++++++---- .../client/src/notifications/edit/edit.controller.js | 12 ++++++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/awx/ui/client/src/notifications/add/add.controller.js b/awx/ui/client/src/notifications/add/add.controller.js index 58dacc5405..0be8962b3f 100644 --- a/awx/ui/client/src/notifications/add/add.controller.js +++ b/awx/ui/client/src/notifications/add/add.controller.js @@ -7,13 +7,13 @@ export default ['Rest', 'Wait', 'NotificationsFormObject', 'ProcessErrors', 'GetBasePath', 'Alert', 'GenerateForm', '$scope', '$state', 'CreateSelect2', 'GetChoices', - 'NotificationsTypeChange', 'ParseTypeChange', 'i18n', 'MessageUtils', + 'NotificationsTypeChange', 'ParseTypeChange', 'i18n', 'MessageUtils', '$filter', function( Rest, Wait, NotificationsFormObject, ProcessErrors, GetBasePath, Alert, GenerateForm, $scope, $state, CreateSelect2, GetChoices, NotificationsTypeChange, ParseTypeChange, i18n, - MessageUtils + MessageUtils, $filter ) { var generator = GenerateForm, @@ -267,10 +267,14 @@ export default ['Rest', 'Wait', 'NotificationsFormObject', $state.go('notifications', {}, { reload: true }); Wait('stop'); }) - .catch(({data, status}) => { + .catch(({ data, status }) => { + let description = 'POST returned status: ' + status; + if (data && data.messages && data.messages.length > 0) { + description = _.uniq(data.messages).join(', '); + } ProcessErrors($scope, data, status, form, { hdr: 'Error!', - msg: 'Failed to add new notifier. POST returned status: ' + status + msg: $filter('sanitize')('Failed to add new notifier. ' + description + '.') }); }); }; diff --git a/awx/ui/client/src/notifications/edit/edit.controller.js b/awx/ui/client/src/notifications/edit/edit.controller.js index 8128cff488..a78b4c9c78 100644 --- a/awx/ui/client/src/notifications/edit/edit.controller.js +++ b/awx/ui/client/src/notifications/edit/edit.controller.js @@ -10,7 +10,7 @@ export default ['Rest', 'Wait', 'notification_template', '$scope', '$state', 'GetChoices', 'CreateSelect2', 'Empty', 'NotificationsTypeChange', 'ParseTypeChange', 'i18n', - 'MessageUtils', + 'MessageUtils', '$filter', function( Rest, Wait, NotificationsFormObject, ProcessErrors, GetBasePath, @@ -18,7 +18,7 @@ export default ['Rest', 'Wait', notification_template, $scope, $state, GetChoices, CreateSelect2, Empty, NotificationsTypeChange, ParseTypeChange, i18n, - MessageUtils + MessageUtils, $filter ) { var generator = GenerateForm, id = notification_template.id, @@ -350,10 +350,14 @@ export default ['Rest', 'Wait', $state.go('notifications', {}, { reload: true }); Wait('stop'); }) - .catch(({data, status}) => { + .catch(({ data, status }) => { + let description = 'PUT returned status: ' + status; + if (data && data.messages && data.messages.length > 0) { + description = _.uniq(data.messages).join(', '); + } ProcessErrors($scope, data, status, form, { hdr: 'Error!', - msg: 'Failed to add new notification template. POST returned status: ' + status + msg: $filter('sanitize')('Failed to update notifier. ' + description + '.') }); }); };