Merge "Refactor error messages"

This commit is contained in:
Zuul 2019-10-15 02:46:24 +00:00 committed by Gerrit Code Review
commit 28793ad0bf
8 changed files with 34 additions and 34 deletions

View File

@ -87,10 +87,10 @@ class CreateForm(forms.SelfHandlingForm):
msg = _('Creating cluster "%s" successfully') % data['name']
messages.success(request, msg)
return cluster
except Exception:
except Exception as e:
redirect = reverse(INDEX_URL)
exceptions.handle(request,
_("Unable to create cluster."),
_("Unable to create cluster: %s") % e,
redirect=redirect)
@ -125,8 +125,8 @@ class ManagePoliciesForm(forms.SelfHandlingForm):
"cluster": data['cluster_id']}
messages.success(request, msg)
return attach
except Exception:
except Exception as e:
redirect = reverse(INDEX_URL)
exceptions.handle(request,
_("Unable to attach policy."),
_("Unable to attach policy: %s") % e,
redirect=redirect)

View File

@ -57,10 +57,10 @@ class IndexView(tables.DataTableView):
paginate=True,
reversed_order=reversed_order,
filters=filters)
except Exception:
except Exception as e:
self._prev = self._more = False
clusters = []
msg = _('Unable to retrieve clusters.')
msg = _('Unable to retrieve clusters: %s') % e
exceptions.handle(self.request, msg)
return clusters
@ -91,8 +91,8 @@ class DetailView(tabs.TabView):
cluster = senlin.cluster_get(self.request, cluster_id)
cluster.profile_url = reverse_lazy(self.profile_url,
args=[cluster.profile_id])
except Exception:
msg = _("Unable to retrieve cluster.")
except Exception as e:
msg = _("Unable to retrieve cluster: %s") % e
url = reverse_lazy(clusters_forms.INDEX_URL)
exceptions.handle(self.request, msg, redirect=url)
return cluster

View File

@ -86,10 +86,10 @@ class CreateForm(forms.SelfHandlingForm):
msg = _('Creating node "%s" successfully') % data['name']
messages.info(request, msg)
return node
except Exception:
except Exception as e:
redirect = reverse("horizon:cluster:nodes:index")
exceptions.handle(request,
_("Unable to create node."),
_("Unable to create node: %s") % e,
redirect=redirect)
@ -133,9 +133,9 @@ class UpdateNodeForm(forms.SelfHandlingForm):
' has been accepted for processing.') %
data['name'])
return node
except Exception:
except Exception as e:
redirect = reverse("horizon:cluster:nodes:index")
exceptions.handle(request,
_("Unable to update node."),
_("Unable to update node: %s") % e,
redirect=redirect)
return False

View File

@ -57,10 +57,10 @@ class IndexView(tables.DataTableView):
paginate=True,
reversed_order=reversed_order,
filters=filters)
except Exception:
except Exception as e:
self._prev = self._more = False
nodes = []
msg = _('Unable to retrieve nodes.')
msg = _('Unable to retrieve nodes: %s') % e
exceptions.handle(self.request, msg)
return nodes
@ -90,8 +90,8 @@ class DetailView(tabs.TabView):
# Get initial node information
node_id = self.kwargs["node_id"]
node = senlin.node_get(self.request, node_id)
except Exception:
msg = _("Unable to retrieve node.")
except Exception as e:
msg = _("Unable to retrieve node: %s") % e
url = reverse_lazy("horizon:cluster:nodes:index")
exceptions.handle(self.request, msg, redirect=url)
return node
@ -145,8 +145,8 @@ class UpdateView(forms.ModalFormView):
"role": node.role,
"metadata": metadata}
except Exception:
msg = _("Unable to retrieve node.")
except Exception as e:
msg = _("Unable to retrieve node: %s") % e
url = reverse_lazy("horizon:cluster:nodes:index")
exceptions.handle(self.request, msg, redirect=url)
return node_dict

View File

@ -91,9 +91,9 @@ class CreatePolicyForm(forms.SelfHandlingForm):
_('Your policy %s has been created.') %
args['name'])
return policy
except Exception:
except Exception as e:
redirect = reverse(INDEX_URL)
msg = _('Unable to create new policy')
msg = _('Unable to create new policy: %s') % e
exceptions.handle(request, msg, redirect=redirect)
return False
@ -114,8 +114,8 @@ class UpdatePolicyForm(forms.SelfHandlingForm):
except ValidationError as e:
self.api_error(e.messages[0])
return False
except Exception:
except Exception as e:
redirect = reverse(INDEX_URL)
msg = _('Unable to update policy')
msg = _('Unable to update policy: %s') % e
exceptions.handle(request, msg, redirect=redirect)
return False

View File

@ -57,10 +57,10 @@ class IndexView(tables.DataTableView):
paginate=True,
reversed_order=reversed_order,
filters=filters)
except Exception:
except Exception as e:
self._prev = self._more = False
policies = []
msg = _('Unable to retrieve policies.')
msg = _('Unable to retrieve policies: %s') % e
exceptions.handle(self.request, msg)
return policies
@ -90,8 +90,8 @@ class DetailView(tabs.TabView):
policy = senlin.policy_get(self.request, policy_id)
policy.policy_spec = yaml.safe_dump(policy.spec,
default_flow_style=False)
except Exception:
msg = _("Unable to retrieve policy.")
except Exception as e:
msg = _("Unable to retrieve policy: %s") % e
url = reverse_lazy(policies_forms.INDEX_URL)
exceptions.handle(self.request, msg, redirect=url)
return policy
@ -129,8 +129,8 @@ class UpdateView(forms.ModalFormView):
policy = senlin.policy_get(self.request, policy_id)
policy_dict = {"policy_id": policy_id,
"name": policy.name}
except Exception:
msg = _("Unable to retrieve policy.")
except Exception as e:
msg = _("Unable to retrieve policy: %s") % e
url = reverse_lazy(policies_forms.INDEX_URL)
exceptions.handle(self.request, msg, redirect=url)
return policy_dict

View File

@ -96,8 +96,8 @@ class CreateReceiverForm(forms.SelfHandlingForm):
_('Your receiver %s has been created successfully.') %
data['name'])
return receiver
except Exception:
except Exception as e:
redirect = reverse(INDEX_URL)
msg = _('Unable to create new receiver')
msg = _('Unable to create new receiver: %s') % e
exceptions.handle(request, msg, redirect=redirect)
return False

View File

@ -55,10 +55,10 @@ class IndexView(tables.DataTableView):
paginate=True,
reversed_order=reversed_order,
filters=filters)
except Exception:
except Exception as e:
self._prev = self._more = False
receivers = []
msg = _('Unable to retrieve receivers.')
msg = _('Unable to retrieve receivers: %s') % e
exceptions.handle(self.request, msg)
return receivers
@ -87,8 +87,8 @@ class DetailView(tabs.TabView):
# Get initial receiver information
receiver_id = self.kwargs["receiver_id"]
receiver = senlin.receiver_get(self.request, receiver_id)
except Exception:
msg = _("Unable to retrieve receiver.")
except Exception as e:
msg = _("Unable to retrieve receiver: %s") % e
url = reverse_lazy("horizon:cluster:receivers:index")
exceptions.handle(self.request, msg, redirect=url)
return receiver