Commit 70ccd32a authored by Romain Courteaud's avatar Romain Courteaud

slap/hateoas: reduce number of errors catched/rewriten by do_request

parent 8600945f
......@@ -131,34 +131,29 @@ class ConnectionHelper:
path = path[1:]
# raise ValueError('method path should be relative: %s' % path)
try:
if url.startswith('https'):
cert = (self.cert_file, self.key_file)
else:
cert = None
# XXX TODO: handle host cert verify
try:
req = method(url=url,
params=params,
cert=cert,
# XXX TODO: handle host cert verify
verify=False,
data=data,
headers=headers,
timeout=self.timeout)
try:
req.raise_for_status()
except TypeError:
# In Py3, a comparison between NoneType and int can occur if req has no
# status_code (= None).
pass
except (requests.Timeout, requests.ConnectionError) as exc:
raise ConnectionError("Couldn't connect to the server. Please "
"double check given master-url argument, and make sure that IPv6 is "
"enabled on your machine and that the server is available. The "
"original error was:\n%s" % exc)
except requests.HTTPError as exc:
raise
# XXX Desactivated by Romain, to get ride of custom slaptool behaviour
"""
if exc.response.status_code == requests.status_codes.codes.not_found:
msg = url
if params:
......@@ -170,7 +165,8 @@ class ConnectionHelper:
# XXX TODO test request timeout and resource not found
else:
# we don't know how or don't want to handle these (including Unauthorized)
req.raise_for_status()
raise
"""
except requests.exceptions.SSLError as exc:
raise AuthenticationError("%s\nCouldn't authenticate computer. Please "
"check that certificate and key exist and are valid." % exc)
......@@ -182,6 +178,14 @@ class ConnectionHelper:
# path)
# raise ServerError(message)
try:
req.raise_for_status()
except TypeError:
# In Py3, a comparison between NoneType and int can occur if req has no
# status_code (= None).
# pass
# XXX Desactivated by Romain, as we expect a status code
raise
return req
def callJsonRpcAPI(self, path, data, cert_key=None):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment