summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Herve <therve@redhat.com>2016-03-09 14:51:07 +0100
committerThomas Herve <therve@redhat.com>2016-03-09 15:23:38 +0100
commit3a4d6ecbcf084a8715842ad9e4e2131c36ce098f (patch)
tree5b13b518b13fc6cddbc0edca21d42cf5aa2b00b1
parent4db1aec97d1d4a51ac013ce0a0c6058e3cb462c2 (diff)
downloadpython-barbicanclient-3a4d6ecbcf084a8715842ad9e4e2131c36ce098f.tar.gz
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
-rw-r--r--barbicanclient/client.py3
-rw-r--r--barbicanclient/tests/test_client.py7
2 files changed, 10 insertions, 0 deletions
diff --git a/barbicanclient/client.py b/barbicanclient/client.py
index 29ab60d..e38276b 100644
--- a/barbicanclient/client.py
+++ b/barbicanclient/client.py
@@ -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
diff --git a/barbicanclient/tests/test_client.py b/barbicanclient/tests/test_client.py
index a27cbc6..e862c5a 100644
--- a/barbicanclient/tests/test_client.py
+++ b/barbicanclient/tests/test_client.py
@@ -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):