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:
Jens Harbott 2017-09-01 10:45:10 +00:00
parent 245ea8deac
commit 5b502b9f78
2 changed files with 8 additions and 1 deletions

View File

@ -36,7 +36,7 @@ class NoUniqueMatch(Base):
class RemoteError(Base):
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)
self.message = err_message
self.code = code

View File

@ -54,3 +54,10 @@ class RemoteErrorTestCase(base.TestCase):
self.response_dict['type'] = expected_msg
remote_err = exceptions.RemoteError(**self.response_dict)
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)