From 44315885507434a4822dda76261796e6042a7c67 Mon Sep 17 00:00:00 2001 From: Danny Hermes Date: Wed, 25 Mar 2015 16:05:42 -0700 Subject: [PATCH] Using correct format of exceptions from JSON based APIs. --- gcloud/exceptions.py | 4 ++-- gcloud/test_exceptions.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/gcloud/exceptions.py b/gcloud/exceptions.py index a2fe8ae6a3f5..dc5458eedccb 100644 --- a/gcloud/exceptions.py +++ b/gcloud/exceptions.py @@ -179,11 +179,11 @@ def make_exception(response, content, use_json=True): if use_json: payload = json.loads(content) else: - payload = {'message': content} + payload = {'error': {'message': content}} else: payload = content - message = payload.get('message', '') + message = payload.get('error', {}).get('message', '') errors = payload.get('error', {}).get('errors', ()) try: diff --git a/gcloud/test_exceptions.py b/gcloud/test_exceptions.py index b2d0ec2f7b0b..d42f8ebef900 100644 --- a/gcloud/test_exceptions.py +++ b/gcloud/test_exceptions.py @@ -55,7 +55,7 @@ def _callFUT(self, response, content): def test_hit_w_content_as_str(self): from gcloud.exceptions import NotFound response = _Response(404) - content = b'{"message": "Not Found"}' + content = b'{"error": {"message": "Not Found"}}' exception = self._callFUT(response, content) self.assertTrue(isinstance(exception, NotFound)) self.assertEqual(exception.message, 'Not Found') @@ -71,7 +71,7 @@ def test_miss_w_content_as_dict(self): 'reason': 'test', } response = _Response(600) - content = {"message": "Unknown Error", "error": {"errors": [ERROR]}} + content = {"error": {"message": "Unknown Error", "errors": [ERROR]}} exception = self._callFUT(response, content) self.assertTrue(isinstance(exception, GCloudError)) self.assertEqual(exception.message, 'Unknown Error')