Fixed problem when connection lost during request executing and nothing was happened, now it raises an exception.

This commit is contained in:
evgeny.ezhov 2017-11-27 22:16:17 +03:00
parent 378afe5890
commit 44ec8fcc66
4 changed files with 35 additions and 3 deletions

View file

@ -68,10 +68,11 @@ def wrap_connection_error(fn):
try:
res = fn(self, *args, **kw)
except requests.ConnectionError:
raise NotConnection(self.webdav.hostname)
raise NoConnection(self.webdav.hostname)
except requests.RequestException as re:
raise ConnectionException(re)
else:
return res
return _wrapper
@ -84,6 +85,9 @@ class Client(object):
# Max size of file for uploading
large_size = 2 * 1024 * 1024 * 1024
# request timeout in seconds
timeout = 30
# HTTP headers for different actions
http_header = {
'list': ["Accept: */*", "Depth: 1"],
@ -155,6 +159,7 @@ class Client(object):
url=self.get_url(path),
auth=(self.webdav.login, self.webdav.password),
headers=self.get_headers(action, headers_ext),
timeout=self.timeout,
data=data
)
if response.status_code == 507:

View file

@ -71,7 +71,15 @@ class MethodNotSupported(WebDavException):
return "Method {name} not supported for {server}".format(name=self.name, server=self.server)
class NotConnection(WebDavException):
class ConnectionException(WebDavException):
def __init__(self, exception):
self.exception = exception
def __str__(self):
return self.exception.__str__()
class NoConnection(WebDavException):
def __init__(self, hostname):
self.hostname = hostname
@ -79,6 +87,15 @@ class NotConnection(WebDavException):
return "Not connection with {hostname}".format(hostname=self.hostname)
# This exception left only for supporting original library interface.
class NotConnection(WebDavException):
def __init__(self, hostname):
self.hostname = hostname
def __str__(self):
return "No connection with {hostname}".format(hostname=self.hostname)
class ResponseErrorCode(WebDavException):
def __init__(self, url, code, message):
self.url = url