commit b4991fcf250eb4c033b19a3b29a175995a97fcfa Author: manchandavishal Date: Thu Aug 27 17:12:25 2020 +0000 Cleanup for Refactor-error-messages This patch is a clean-up patch for refactor-error-messages bp which remove the exception message from base message otherwise the same exception message display twice like this https://ibb.co/XyFWMdz . Depends-On: https://review.opendev.org/#/c/708069/ Change-Id: I1ddea97cdcaf4142d9dabcf4a629e805a9c1e152 diff --git a/monitoring/alarmdefs/forms.py b/monitoring/alarmdefs/forms.py index 65c7119..dc18f2a 100644 --- a/monitoring/alarmdefs/forms.py +++ b/monitoring/alarmdefs/forms.py @@ -240,10 +240,10 @@ class EditAlarmForm(forms.SelfHandlingForm): def set_notification_choices(self, request): try: notifications = api.monitor.notification_list(request) - except Exception as e: + except Exception: notifications = [] exceptions.handle(request, - _('Unable to retrieve notifications: %s') % e) + _('Unable to retrieve notifications.')) notification_choices = [ (notification['id'], notification) for notification in notifications] @@ -267,7 +267,8 @@ class EditAlarmForm(forms.SelfHandlingForm): ) messages.success(request, _('Alarm definition has been updated.')) - except Exception as e: - exceptions.handle(request, _('%s') % e) + except Exception: + exceptions.handle(request, + _('Unable to update alarm definition.')) return False return True diff --git a/monitoring/alarmdefs/workflows.py b/monitoring/alarmdefs/workflows.py index 690a2ba..b04a356 100644 --- a/monitoring/alarmdefs/workflows.py +++ b/monitoring/alarmdefs/workflows.py @@ -62,9 +62,9 @@ class SetAlarmNotificationsAction(workflows.Action): try: notifications = ad_forms._get_notifications(request) self.fields['notifications'].choices = notifications - except Exception as e: + except Exception: exceptions.handle(request, - _('Unable to retrieve notifications: %s') % e) + _('Unable to retrieve notifications.')) _SEVERITY_CHOICES = [("LOW", _("Low")), @@ -221,8 +221,10 @@ class AlarmDefinitionWorkflow(workflows.Workflow): ok_actions=context['ok_actions'], undetermined_actions=context['undetermined_actions'], ) - except Exception as e: - exceptions.handle(request, e, escalate=True) + except Exception: + exceptions.handle(request, + _('Unable to create alarm definition.'), + escalate=True) return False return True diff --git a/monitoring/alarms/forms.py b/monitoring/alarms/forms.py index 9424b78..ba2dffe 100644 --- a/monitoring/alarms/forms.py +++ b/monitoring/alarms/forms.py @@ -213,10 +213,10 @@ class BaseAlarmForm(forms.SelfHandlingForm): def set_notification_choices(self, request): try: notifications = api.monitor.notification_list(request) - except Exception as e: + except Exception: notifications = [] exceptions.handle(request, - _('Unable to retrieve notifications: %s') % e) + _('Unable to retrieve notifications.')) notification_choices = [(notification['id'], notification['name']) for notification in notifications] if notification_choices: @@ -264,8 +264,8 @@ class CreateAlarmForm(BaseAlarmForm): ) messages.success(request, _('Alarm has been created successfully.')) - except Exception as e: - exceptions.handle(request, _('Unable to create the alarm: %s') % e.message) + except Exception: + exceptions.handle(request, _('Unable to create the alarm.')) return False return True @@ -298,7 +298,7 @@ class EditAlarmForm(BaseAlarmForm): ) messages.success(request, _('Alarm has been edited successfully.')) - except Exception as e: - exceptions.handle(request, _('Unable to edit the alarm: %s') % e) + except Exception: + exceptions.handle(request, _('Unable to edit the alarm.')) return False return True diff --git a/monitoring/notifications/forms.py b/monitoring/notifications/forms.py index aa6355f..188523a 100644 --- a/monitoring/notifications/forms.py +++ b/monitoring/notifications/forms.py @@ -118,10 +118,9 @@ class CreateMethodForm(BaseNotificationMethodForm): messages.success(request, _('Notification method has been created ' 'successfully.')) - except Exception as e: + except Exception: exceptions.handle(request, - _('Unable to create the notification ' - 'method: %s') % e) + _('Unable to create the notification method.')) return False return True @@ -154,8 +153,8 @@ class EditMethodForm(BaseNotificationMethodForm): ) messages.success(request, _('Notification has been edited successfully.')) - except Exception as e: + except Exception: exceptions.handle(request, - _('Unable to edit the notification: %s') % e) + _('Unable to edit the notification.')) return False return True diff --git a/monitoring/notifications/tables.py b/monitoring/notifications/tables.py index d52fdb4..89a7082 100644 --- a/monitoring/notifications/tables.py +++ b/monitoring/notifications/tables.py @@ -49,11 +49,9 @@ class DeleteNotification(tables.DeleteAction): def delete(self, request, obj_id): try: api.monitor.notification_delete(request, obj_id) - except Exception as e: + except Exception: exceptions.handle( - request, - _('Unable to delete notification: %s') % - e) + request, _('Unable to delete notification.')) class CreateNotification(tables.LinkAction):