Commit 1e266062 authored by Michal Čihař's avatar Michal Čihař

Share code for error login in machine translation backends

Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 6c9065d9
...@@ -158,6 +158,22 @@ class MachineTranslation(object): ...@@ -158,6 +158,22 @@ class MachineTranslation(object):
''' '''
return language return language
def report_error(self, exc, message):
"""Wrapper for handling error situations"""
report_error(
exc, sys.exc_info(),
{'mt_url': self.request_url, 'mt_params': self.request_params}
)
LOGGER.error(
message,
self.name,
)
LOGGER.error(
'Last fetched URL: %s, params: %s',
self.request_url,
self.request_params,
)
@property @property
def supported_languages(self): def supported_languages(self):
''' '''
...@@ -174,18 +190,9 @@ class MachineTranslation(object): ...@@ -174,18 +190,9 @@ class MachineTranslation(object):
try: try:
languages = self.download_languages() languages = self.download_languages()
except Exception as exc: except Exception as exc:
report_error( self.report_error(
exc, sys.exc_info(), exc,
{'mt_url': self.request_url, 'mt_params': self.request_params}
)
LOGGER.error(
'Failed to fetch languages from %s, using defaults', 'Failed to fetch languages from %s, using defaults',
self.name,
)
LOGGER.error(
'Last fetched URL: %s, params: %s',
self.request_url,
self.request_params,
) )
if settings.DEBUG: if settings.DEBUG:
raise raise
...@@ -227,18 +234,9 @@ class MachineTranslation(object): ...@@ -227,18 +234,9 @@ class MachineTranslation(object):
for trans in translations for trans in translations
] ]
except Exception as exc: except Exception as exc:
report_error( self.report_error(
exc, sys.exc_info(), exc,
{'mt_url': self.request_url, 'mt_params': self.request_params}
)
LOGGER.error(
'Failed to fetch translations from %s', 'Failed to fetch translations from %s',
self.name,
)
LOGGER.error(
'Last fetched URL: %s, params: %s',
self.request_url,
self.request_params,
) )
raise MachineTranslationError('{}: {}'.format( raise MachineTranslationError('{}: {}'.format(
exc.__class__.__name__, exc.__class__.__name__,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment