From 1c1dac9aa6f0e8fcf5e35a3d15d47ed483744fad Mon Sep 17 00:00:00 2001 From: manchandavishal Date: Thu, 27 Aug 2020 17:12:25 +0000 Subject: [PATCH] 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: I4e0f50b95b7c94cf641fc778268b6c4c1267175c --- muranodashboard/environments/tables.py | 15 ++++++--------- muranodashboard/packages/forms.py | 19 ++----------------- .../tests/unit/packages/test_forms.py | 2 +- 3 files changed, 9 insertions(+), 27 deletions(-) diff --git a/muranodashboard/environments/tables.py b/muranodashboard/environments/tables.py index f41e92dda..a5f6aef6b 100644 --- a/muranodashboard/environments/tables.py +++ b/muranodashboard/environments/tables.py @@ -100,9 +100,8 @@ class CreateEnvironment(tables.LinkAction): def action(self, request, environment): try: api.environment_create(request, environment) - except Exception as e: - msg = (_('Unable to create environment {0}' - ' due to: {1}').format(environment, e)) + except Exception: + msg = _('Unable to create environment "%s".') % environment LOG.error(msg) redirect = reverse(self.redirect_url) exceptions.handle(request, msg, redirect=redirect) @@ -153,9 +152,8 @@ class DeleteEnvironment(policy.PolicyTargetMixin, tables.DeleteAction): def action(self, request, environment_id): try: api.environment_delete(request, environment_id) - except Exception as e: - msg = (_('Unable to delete environment {0}' - ' due to: {1}').format(environment_id, e)) + except Exception: + msg = _('Unable to delete environment "%s".') % environment_id LOG.error(msg) redirect = reverse(self.redirect_url) exceptions.handle(request, msg, redirect=redirect) @@ -209,9 +207,8 @@ class AbandonEnvironment(tables.DeleteAction): def action(self, request, environment_id): try: api.environment_delete(request, environment_id, True) - except Exception as e: - msg = (_('Unable to abandon an environment {0}' - ' due to: {1}').format(environment_id, e)) + except Exception: + msg = _('Unable to abandon the environment "%s".') % environment_id LOG.error(msg) redirect = reverse(self.redirect_url) exceptions.handle(request, msg, redirect=redirect) diff --git a/muranodashboard/packages/forms.py b/muranodashboard/packages/forms.py index 6d4216cc6..8d9de1eba 100644 --- a/muranodashboard/packages/forms.py +++ b/muranodashboard/packages/forms.py @@ -12,9 +12,6 @@ # License for the specific language governing permissions and limitations # under the License. -import json -import sys - from django.core import validators from django import forms from django.urls import reverse @@ -252,20 +249,8 @@ class ModifyPackageForm(PackageParamsMixin, horizon_forms.SelfHandlingForm): request, msg, redirect=reverse('horizon:app-catalog:packages:index')) - except Exception as original_e: - reason = '' - - exc_info = sys.exc_info() - if hasattr(original_e, 'details'): - try: - error = json.loads(original_e.details).get('error') - if error: - reason = error.get('message') - except ValueError: - # Let horizon operate with original exception - raise (exc_info[0], exc_info[1], exc_info[2]) - - msg = _('Failed to modify the package. {0}').format(reason) + except Exception: + msg = _('Failed to modify the package.') LOG.exception(msg) redirect = reverse('horizon:app-catalog:packages:index') exceptions.handle(request, diff --git a/muranodashboard/tests/unit/packages/test_forms.py b/muranodashboard/tests/unit/packages/test_forms.py index 55e4bdc31..5e4a48406 100644 --- a/muranodashboard/tests/unit/packages/test_forms.py +++ b/muranodashboard/tests/unit/packages/test_forms.py @@ -252,7 +252,7 @@ class TestModifyPackageForm(helpers.APITestCase): 'horizon:app-catalog:packages:index') mock_exceptions.handle.assert_called_once_with( self.mock_request, - 'Failed to modify the package. {0}'.format('test_error_message'), + 'Failed to modify the package.', redirect='test_redirect')