Skip to content
This repository was archived by the owner on May 9, 2020. It is now read-only.

Commit 2f630f5

Browse files
committed
Merge pull request #47 from cread/fix_requests_error_handling
Fix role tests and error handling with requests
2 parents 001b94b + 7d2b1f8 commit 2f630f5

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

chef/api.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -201,15 +201,14 @@ def request(self, method, path, headers={}, data=None):
201201
try:
202202
response = self._request(method, self.url + path, data, dict(
203203
(k.capitalize(), v) for k, v in six.iteritems(request_headers)))
204-
except six.moves.urllib.error.HTTPError as e:
205-
e.content = e.read()
206-
try:
207-
e.content = json.loads(e.content.decode())
208-
raise ChefServerError.from_error(e.content['error'], code=e.code)
209-
except ValueError:
210-
pass
211-
raise e
212-
return response
204+
except requests.ConnectionError as e:
205+
raise ChefServerError(e.message)
206+
207+
if response.ok:
208+
return response
209+
210+
raise ChefServerError.from_error(response.reason, code=response.status_code)
211+
213212

214213
def api_request(self, method, path, headers={}, data=None):
215214
headers = dict((k.lower(), v) for k, v in six.iteritems(headers))

0 commit comments

Comments
 (0)