Refactor error messages

This patchrefactoring the error message and
shows the detailed error message

Change-Id: I95c33f7e02bab5f26f0a883f01eac379cf24dea9
This commit is contained in:
pengyuesheng 2019-09-06 16:07:38 +08:00
parent 5f84a726d7
commit 4867842a5e
5 changed files with 37 additions and 22 deletions

View File

@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import six
from django.urls import reverse
from django.utils.translation import ugettext_lazy as _
from horizon import exceptions
@ -168,8 +170,8 @@ class CreateForm(forms.SelfHandlingForm):
messages.success(request,
_('Application was successfully created.'))
return True
except Exception:
msg = _('Unable to create application')
except Exception as e:
msg = _('Unable to create application: %s') % six.text_type(e)
redirect = reverse("horizon:solum:applications:index")
exceptions.handle(request, msg, redirect=redirect)
return False

View File

@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import six
from django.urls import reverse
from django.urls import reverse_lazy
from django.utils.translation import ugettext_lazy as _
@ -39,10 +41,11 @@ class IndexView(tables.DataTableView):
try:
solum = solumclient(self.request)
apps = solum.apps.list()
except Exception:
except Exception as e:
apps = []
exceptions.handle(self.request,
_('Unable to retrieve apps.'))
exceptions.handle(
self.request,
_('Unable to retrieve apps: %s') % six.text_type(e))
return apps
@ -107,11 +110,12 @@ class DetailView(tabs.TabView):
try:
solum = solumclient(self.request)
app = solum.apps.find(name_or_id=application_id)
except Exception:
except Exception as e:
INDEX_URL = 'horizon:solum:applications:index'
exceptions.handle(self.request,
_('Unable to retrieve application details.'),
redirect=reverse(INDEX_URL))
exceptions.handle(
self.request,
_('Unable to retrieve application details: %s') % str(e),
redirect=reverse(INDEX_URL))
context["app"] = app
table = app_tables.ApplicationsTable(self.request)
context["actions"] = table.render_row_actions(app)

View File

@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import six
from django.utils.translation import ugettext_lazy as _
from horizon import exceptions
@ -33,9 +35,11 @@ class IndexView(tables.DataTableView):
try:
solum = solumclient(self.request)
assemblies = solum.assemblies.list()
except Exception:
except Exception as e:
assemblies = []
exceptions.handle(self.request, 'Unable to retrieve assemblies.')
exceptions.handle(
self.request,
_('Unable to retrieve assemblies: %s') % six.type(e))
return assemblies

View File

@ -14,6 +14,7 @@
# limitations under the License.
import json
import six
from django.urls import reverse
from django.utils.translation import ugettext_lazy as _
@ -63,10 +64,11 @@ class CreateForm(forms.SelfHandlingForm):
message = _(
'Languagepack %s was successfully created.') % data['name']
messages.success(request, message)
except Exception:
except Exception as e:
redirect = reverse('horizon:solum:languagepacks:index')
exceptions.handle(self.request,
_('Unable to create languagepack.'),
redirect=redirect)
exceptions.handle(
self.request,
_('Unable to create languagepack: %s') % six.text_type(e),
redirect=redirect)
return True

View File

@ -18,6 +18,7 @@ from django.urls import reverse_lazy
from django.utils.translation import ugettext_lazy as _
import json
import six
from horizon import exceptions
from horizon import forms
@ -40,10 +41,11 @@ class IndexView(tables.DataTableView):
try:
solum = solumclient(self.request)
languagepacks = solum.languagepacks.list()
except Exception:
except Exception as e:
languagepacks = []
exceptions.handle(self.request,
_('Unable to retrieve languagepacks.'))
exceptions.handle(
self.request,
_('Unable to retrieve languagepacks: %s') % six.text_type(e))
return languagepacks
@ -70,11 +72,12 @@ class DetailView(views.HorizonTemplateView):
languagepack = solum.languagepacks.find(name_or_id=lp_id)
loglist = cli_lp.LanguagePackManager(solum).logs(
lp_id=lp_id)
except Exception:
except Exception as e:
INDEX_URL = 'horizon:solum:languagepacks:index'
exceptions.handle(self.request,
_('Unable to retrieve languagepack details.'),
redirect=reverse(INDEX_URL))
exceptions.handle(
self.request,
_('Unable to retrieve languagepack details: %s') % str(e),
redirect=reverse(INDEX_URL))
for log in loglist:
strategy_info = json.loads(log.strategy_info)