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

Commit

Permalink
Fix role tests and error handling with requests
Browse files Browse the repository at this point in the history
  • Loading branch information
cread committed Nov 24, 2015
1 parent 5270648 commit 7d2b1f8
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions chef/api.py
Expand Up @@ -201,15 +201,14 @@ def request(self, method, path, headers={}, data=None):
try:
response = self._request(method, self.url + path, data, dict(
(k.capitalize(), v) for k, v in six.iteritems(request_headers)))
except six.moves.urllib.error.HTTPError as e:
e.content = e.read()
try:
e.content = json.loads(e.content.decode())
raise ChefServerError.from_error(e.content['error'], code=e.code)
except ValueError:
pass
raise e
return response
except requests.ConnectionError as e:
raise ChefServerError(e.message)

if response.ok:
return response

raise ChefServerError.from_error(response.reason, code=response.status_code)


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

0 comments on commit 7d2b1f8

Please sign in to comment.