Removed the '_safe_message' variable from the API exceptions
The variable _safe_message is linked to logic that is either no longer used or not implemented. Removing the variable is a part of improving the exception message by using 1 source to generate the exception message Partially Implements: blueprint improve-error-message-details-for-usability Change-Id: Ied1acf22790cdedad685990fc628462d51b1477e
This commit is contained in:
parent
adfec54572
commit
a545a4b63e
@ -219,7 +219,7 @@ def check_message(keywords, message):
|
||||
"""
|
||||
exc_type, exc_value, exc_traceback = sys.exc_info()
|
||||
if set(str(exc_value).split(" ")).issuperset(set(keywords)):
|
||||
exc_value._safe_message = message
|
||||
exc_value.message = message
|
||||
raise
|
||||
|
||||
|
||||
@ -337,9 +337,6 @@ def handle(request, message=None, redirect=None, ignore=False,
|
||||
# We trust messages from our own exceptions
|
||||
if issubclass(exc_type, HorizonException):
|
||||
message = exc_value
|
||||
# Check for an override message
|
||||
elif getattr(exc_value, "_safe_message", None):
|
||||
message = exc_value._safe_message
|
||||
# If the message has a placeholder for the exception, fill it in
|
||||
elif message and "%(exc)s" in message:
|
||||
message = encoding.force_text(message) % {"exc": log_entry}
|
||||
|
@ -29,7 +29,6 @@ from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils.translation import ungettext_lazy
|
||||
import six
|
||||
|
||||
from horizon import exceptions
|
||||
from horizon import messages
|
||||
from horizon.utils import functions
|
||||
from horizon.utils import html
|
||||
@ -803,9 +802,9 @@ class BatchAction(Action):
|
||||
datum_display = table.get_object_display(datum) or datum_id
|
||||
if not table._filter_action(self, request, datum):
|
||||
action_not_allowed.append(datum_display)
|
||||
LOG.info('Permission denied to %s: "%s"' %
|
||||
(self._get_action_name(past=True).lower(),
|
||||
datum_display))
|
||||
LOG.warning('Permission denied to %s: "%s"' %
|
||||
(self._get_action_name(past=True).lower(),
|
||||
datum_display))
|
||||
continue
|
||||
try:
|
||||
self.action(request, datum_id)
|
||||
@ -819,12 +818,10 @@ class BatchAction(Action):
|
||||
# Handle the exception but silence it since we'll display
|
||||
# an aggregate error message later. Otherwise we'd get
|
||||
# multiple error messages displayed to the user.
|
||||
if getattr(ex, "_safe_message", None):
|
||||
ignore = False
|
||||
else:
|
||||
ignore = True
|
||||
action_failure.append(datum_display)
|
||||
exceptions.handle(request, ignore=ignore)
|
||||
action_failure.append(datum_display)
|
||||
LOG.warning('Action %s Failed for %s' %
|
||||
(self._get_action_name(past=True).lower(),
|
||||
datum_display), ex)
|
||||
|
||||
# Begin with success message class, downgrade to info if problems.
|
||||
success_message_level = messages.success
|
||||
|
@ -38,7 +38,7 @@ class MessageTests(test.TestCase):
|
||||
self.assertEqual(json.dumps([expected]),
|
||||
res['X-Horizon-Messages'])
|
||||
|
||||
def test_safe_message(self):
|
||||
def test_error_message(self):
|
||||
req = self.request
|
||||
string = mark_safe("We are now safe from ants! Go <a>here</a>!")
|
||||
expected = ["error", force_text(string), " safe"]
|
||||
|
@ -204,7 +204,6 @@ def swift_delete_container(request, name):
|
||||
error_msg = _("The container cannot be deleted "
|
||||
"since it is not empty.")
|
||||
exc = exceptions.Conflict(error_msg)
|
||||
exc._safe_message = error_msg
|
||||
raise exc
|
||||
swift_api(request).delete_container(name)
|
||||
return True
|
||||
@ -321,7 +320,6 @@ def swift_delete_object(request, container_name, object_name):
|
||||
error_msg = _("The pseudo folder cannot be deleted "
|
||||
"since it is not empty.")
|
||||
exc = exceptions.Conflict(error_msg)
|
||||
exc._safe_message = error_msg
|
||||
raise exc
|
||||
swift_api(request).delete_object(container_name, object_name)
|
||||
return True
|
||||
|
@ -33,7 +33,6 @@ from openstack_dashboard.dashboards.project.containers import utils
|
||||
from openstack_dashboard.dashboards.project.containers import views
|
||||
from openstack_dashboard.test import helpers as test
|
||||
|
||||
from horizon import exceptions
|
||||
from horizon.utils.urlresolvers import reverse # noqa
|
||||
|
||||
|
||||
@ -108,13 +107,9 @@ class SwiftTests(test.TestCase):
|
||||
req.META['HTTP_REFERER'] = '%s/%s' % (CONTAINER_INDEX_URL,
|
||||
container.name)
|
||||
table = tables.ContainersTable(req, self.containers.list())
|
||||
handled = table.maybe_handle()
|
||||
|
||||
# I'd prefer to call a self.assertRedirectnoFollow,
|
||||
# but constructing the response object is a different paradigm
|
||||
# from constructing the table and calling the maybe_handle method.
|
||||
# I'd appreciate any suggestions on how this should properly be done.
|
||||
self.assertRaises(exceptions.Http302, table.maybe_handle)
|
||||
|
||||
self.assertEqual(handled.status_code, 302)
|
||||
self.assertEqual(unicode(list(req._messages)[0].message),
|
||||
u"The container cannot be deleted "
|
||||
u"since it is not empty.")
|
||||
|
Loading…
Reference in New Issue
Block a user