Display error description
When an error happens, display both the title and the description of the returned error if they exist, to give more context to the user. Change-Id: I84457bfe2d55a877e72a7fcb6dd6ba54c557c45e Closes-Bug: #1555102
This commit is contained in:
@@ -113,6 +113,9 @@ class _HTTPClient(adapter.Adapter):
|
||||
try:
|
||||
response_data = resp.json()
|
||||
message = response_data['title']
|
||||
description = response_data.get('description')
|
||||
if description:
|
||||
message = '{0}: {1}'.format(message, description)
|
||||
except ValueError:
|
||||
message = resp.content
|
||||
return message
|
||||
|
||||
@@ -265,6 +265,13 @@ class WhenTestingGetErrorMessage(TestClient):
|
||||
msg = self.httpclient._get_error_message(resp)
|
||||
self.assertEqual(msg, content)
|
||||
|
||||
def test_gets_error_message_from_description_in_json(self):
|
||||
resp = mock.MagicMock()
|
||||
resp.json.return_value = {'title': 'test_text',
|
||||
'description': 'oopsie'}
|
||||
msg = self.httpclient._get_error_message(resp)
|
||||
self.assertEqual(msg, 'test_text: oopsie')
|
||||
|
||||
|
||||
class BaseEntityResource(testtools.TestCase):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user