Fixing searching errors in mistral.exceptions
* Keep the original exception and reraise Closes-Bug: #1460669 Change-Id: Ieb3e55b4ceb4051e9f1c2a82b2228b34d3195bda
This commit is contained in:
parent
ba5b18c5f5
commit
864e01b284
@ -227,6 +227,12 @@ class EngineServer(object):
|
|||||||
return self._engine.resume_workflow(execution_id)
|
return self._engine.resume_workflow(execution_id)
|
||||||
|
|
||||||
|
|
||||||
|
def _wrap_exception_and_reraise(exception):
|
||||||
|
message = "%s: %s" % (exception.__class__.__name__, exception.message)
|
||||||
|
|
||||||
|
raise exc.MistralException(message)
|
||||||
|
|
||||||
|
|
||||||
def wrap_messaging_exception(method):
|
def wrap_messaging_exception(method):
|
||||||
"""This decorator unwrap remote error in one of MistralException.
|
"""This decorator unwrap remote error in one of MistralException.
|
||||||
|
|
||||||
@ -242,9 +248,14 @@ def wrap_messaging_exception(method):
|
|||||||
try:
|
try:
|
||||||
return method(*args, **kwargs)
|
return method(*args, **kwargs)
|
||||||
|
|
||||||
except client.RemoteError as e:
|
except exc.MistralException:
|
||||||
exc_cls = getattr(exc, e.exc_type)
|
raise
|
||||||
raise exc_cls(e.value)
|
except (client.RemoteError, Exception) as e:
|
||||||
|
if hasattr(e, 'exc_type') and hasattr(exc, e.exc_type):
|
||||||
|
exc_cls = getattr(exc, e.exc_type)
|
||||||
|
raise exc_cls(e.value)
|
||||||
|
|
||||||
|
_wrap_exception_and_reraise(e)
|
||||||
|
|
||||||
return decorator
|
return decorator
|
||||||
|
|
||||||
|
@ -440,3 +440,18 @@ class DefaultEngineWithTransportTest(eng_test_base.EngineTestCase):
|
|||||||
{},
|
{},
|
||||||
'some_description'
|
'some_description'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_engine_client_remote_error_arbitrary(self):
|
||||||
|
mocked = mock.Mock()
|
||||||
|
mocked.call.side_effect = KeyError('wrong key')
|
||||||
|
self.engine_client._client = mocked
|
||||||
|
|
||||||
|
exception = self.assertRaises(
|
||||||
|
exc.MistralException,
|
||||||
|
self.engine_client.start_workflow,
|
||||||
|
'some_wf',
|
||||||
|
{},
|
||||||
|
'some_description'
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertIn('KeyError: wrong key', exception.message)
|
||||||
|
Loading…
Reference in New Issue
Block a user