handle message validation errors

This commit is contained in:
Jake McDermott 2019-08-16 10:17:43 -04:00 committed by Jim Ladd
parent 2b792573f8
commit d068fef767
2 changed files with 16 additions and 8 deletions

View File

@ -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 + '.')
});
});
};

View File

@ -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 + '.')
});
});
};