Merge "Use correct parameter when handling exceptions"

This commit is contained in:
Jenkins 2016-03-24 11:20:58 +00:00 committed by Gerrit Code Review
commit b31f3c3665
1 changed files with 12 additions and 3 deletions

View File

@ -23,6 +23,7 @@ from django.template.defaultfilters import date as django_date
from django.utils.translation import ugettext_lazy as _
from horizon import exceptions
from horizon import get_user_home
LOG = logging.getLogger(__name__)
@ -190,15 +191,23 @@ def shield(message, redirect=''):
def wrap(function):
@wraps(function)
def wrapped_function(request, *args, **kwargs):
def wrapped_function(view, *args, **kwargs):
try:
return function(request, *args, **kwargs)
return function(view, *args, **kwargs)
except Exception as error:
LOG.error(error.message)
namespace = "horizon:disaster_recovery:"
r = reverse("{0}{1}".format(namespace, redirect))
exceptions.handle(request, _(message), redirect=r)
if view.request.path == r:
# To avoid an endless loop, we must not redirect to the
# same page on which the error happened
user_home = get_user_home(view.request.user)
exceptions.handle(view.request, _(message),
redirect=user_home)
else:
exceptions.handle(view.request, _(message), redirect=r)
return wrapped_function
return wrap