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: ...@@ -131,34 +131,29 @@ class ConnectionHelper:
path = path[1:] path = path[1:]
# raise ValueError('method path should be relative: %s' % path) # raise ValueError('method path should be relative: %s' % path)
try:
if url.startswith('https'): if url.startswith('https'):
cert = (self.cert_file, self.key_file) cert = (self.cert_file, self.key_file)
else: else:
cert = None cert = None
# XXX TODO: handle host cert verify try:
req = method(url=url, req = method(url=url,
params=params, params=params,
cert=cert, cert=cert,
# XXX TODO: handle host cert verify
verify=False, verify=False,
data=data, data=data,
headers=headers, headers=headers,
timeout=self.timeout) 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: except (requests.Timeout, requests.ConnectionError) as exc:
raise ConnectionError("Couldn't connect to the server. Please " raise ConnectionError("Couldn't connect to the server. Please "
"double check given master-url argument, and make sure that IPv6 is " "double check given master-url argument, and make sure that IPv6 is "
"enabled on your machine and that the server is available. The " "enabled on your machine and that the server is available. The "
"original error was:\n%s" % exc) "original error was:\n%s" % exc)
except requests.HTTPError as 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: if exc.response.status_code == requests.status_codes.codes.not_found:
msg = url msg = url
if params: if params:
...@@ -170,7 +165,8 @@ class ConnectionHelper: ...@@ -170,7 +165,8 @@ class ConnectionHelper:
# XXX TODO test request timeout and resource not found # XXX TODO test request timeout and resource not found
else: else:
# we don't know how or don't want to handle these (including Unauthorized) # 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: except requests.exceptions.SSLError as exc:
raise AuthenticationError("%s\nCouldn't authenticate computer. Please " raise AuthenticationError("%s\nCouldn't authenticate computer. Please "
"check that certificate and key exist and are valid." % exc) "check that certificate and key exist and are valid." % exc)
...@@ -182,6 +178,14 @@ class ConnectionHelper: ...@@ -182,6 +178,14 @@ class ConnectionHelper:
# path) # path)
# raise ServerError(message) # 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 return req
def callJsonRpcAPI(self, path, data, cert_key=None): 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