Make remote error handling more robust
When a RemoteError is created, it is passed the complete content of the json response from the server. Thus is can happen that it contains unexpected entries, we should just ignore them. Change-Id: I2155d1d44432884f19ef926c02b9d0f99ade57d9 Closes-Bug: 1714460
This commit is contained in:
parent
245ea8deac
commit
5b502b9f78
@ -36,7 +36,7 @@ class NoUniqueMatch(Base):
|
|||||||
|
|
||||||
class RemoteError(Base):
|
class RemoteError(Base):
|
||||||
def __init__(self, message=None, code=None, type=None, errors=None,
|
def __init__(self, message=None, code=None, type=None, errors=None,
|
||||||
request_id=None):
|
request_id=None, **ignore):
|
||||||
err_message = self._get_error_message(message, type, errors)
|
err_message = self._get_error_message(message, type, errors)
|
||||||
self.message = err_message
|
self.message = err_message
|
||||||
self.code = code
|
self.code = code
|
||||||
|
@ -54,3 +54,10 @@ class RemoteErrorTestCase(base.TestCase):
|
|||||||
self.response_dict['type'] = expected_msg
|
self.response_dict['type'] = expected_msg
|
||||||
remote_err = exceptions.RemoteError(**self.response_dict)
|
remote_err = exceptions.RemoteError(**self.response_dict)
|
||||||
self.assertEqual(expected_msg, remote_err.message)
|
self.assertEqual(expected_msg, remote_err.message)
|
||||||
|
|
||||||
|
def test_get_error_message_with_unknown_response(self):
|
||||||
|
expected_msg = 'invalid_object'
|
||||||
|
self.response_dict['message'] = expected_msg
|
||||||
|
self.response_dict['unknown'] = 'fake'
|
||||||
|
remote_err = exceptions.RemoteError(**self.response_dict)
|
||||||
|
self.assertEqual(expected_msg, remote_err.message)
|
||||||
|
Loading…
Reference in New Issue
Block a user