Skip to content

Commit 6f2796c

Browse files
committed
Use 'make_exception' from 'datastore.connection.Connection._request'.
Fixes #508.
1 parent e80e21a commit 6f2796c

2 files changed

Lines changed: 10 additions & 13 deletions

File tree

gcloud/datastore/connection.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414

1515
"""Connections to gcloud datastore API servers."""
1616

17-
import six
18-
1917
from gcloud import connection
18+
from gcloud.exceptions import make_exception
2019
from gcloud.datastore import _datastore_v1_pb2 as datastore_pb
2120
from gcloud.datastore import helpers
2221

@@ -54,7 +53,7 @@ def _request(self, dataset_id, method, data):
5453
5554
:rtype: string
5655
:returns: The string response content from the API call.
57-
:raises: :class:`six.moves.http_client.HTTPException` if the response
56+
:raises: :class:`gcloud.exceptions.GCloudError` if the response
5857
code is not 200 OK.
5958
"""
6059
headers = {
@@ -68,9 +67,7 @@ def _request(self, dataset_id, method, data):
6867

6968
status = headers['status']
7069
if status != '200':
71-
message = ('Request failed with status code %s. '
72-
'Error was: %s' % (status, content))
73-
raise six.moves.http_client.HTTPException(message)
70+
raise make_exception(headers, content)
7471

7572
return content
7673

gcloud/datastore/test_connection.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,16 @@ def test__request_w_200(self):
100100
self.assertEqual(http._called_with['body'], DATA)
101101

102102
def test__request_not_200(self):
103-
import six
103+
from gcloud.exceptions import BadRequest
104104

105105
DATASET_ID = 'DATASET'
106106
METHOD = 'METHOD'
107107
DATA = 'DATA'
108108
conn = self._makeOne()
109-
conn._http = Http({'status': '400'}, 'Bad Request')
110-
with self.assertRaises(six.moves.http_client.HTTPException) as e:
109+
conn._http = Http({'status': '400'}, '{"message": "Bad Request"}')
110+
with self.assertRaises(BadRequest) as e:
111111
conn._request(DATASET_ID, METHOD, DATA)
112-
expected_message = ('Request failed with status code 400. '
113-
'Error was: Bad Request')
112+
expected_message = ('400 Bad Request')
114113
self.assertEqual(str(e.exception), expected_message)
115114

116115
def test__rpc(self):
@@ -845,12 +844,13 @@ class Http(object):
845844
_called_with = None
846845

847846
def __init__(self, headers, content):
848-
self._headers = headers
847+
from httplib2 import Response
848+
self._response = Response(headers)
849849
self._content = content
850850

851851
def request(self, **kw):
852852
self._called_with = kw
853-
return self._headers, self._content
853+
return self._response, self._content
854854

855855

856856
class HttpMultiple(object):

0 commit comments

Comments
 (0)