Skip to content

Commit

Permalink
Using correct format of exceptions from JSON based APIs.
Browse files Browse the repository at this point in the history
  • Loading branch information
dhermes committed Mar 25, 2015
1 parent 1b94f9f commit 4431588
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions gcloud/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions gcloud/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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')
Expand Down

0 comments on commit 4431588

Please sign in to comment.