Introducing a ConnectionTimeout as a subclass of ConnectionError
This is to enable #128 to work
This commit is contained in:
@@ -6,7 +6,7 @@ except ImportError:
|
||||
REQUESTS_AVAILABLE = False
|
||||
|
||||
from .base import Connection
|
||||
from ..exceptions import ConnectionError, ImproperlyConfigured
|
||||
from ..exceptions import ConnectionError, ImproperlyConfigured, ConnectionTimeout
|
||||
from ..compat import urlencode
|
||||
|
||||
class RequestsHttpConnection(Connection):
|
||||
@@ -44,7 +44,10 @@ class RequestsHttpConnection(Connection):
|
||||
response = self.session.request(method, url, data=body, timeout=timeout or self.timeout)
|
||||
duration = time.time() - start
|
||||
raw_data = response.text
|
||||
except (requests.ConnectionError, requests.Timeout) as e:
|
||||
except requests.Timeout as e:
|
||||
self.log_request_fail(method, url, body, time.time() - start, exception=e)
|
||||
raise ConnectionTimeout('TIMEOUT', str(e), e)
|
||||
except requests.ConnectionError as e:
|
||||
self.log_request_fail(method, url, body, time.time() - start, exception=e)
|
||||
raise ConnectionError('N/A', str(e), e)
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import time
|
||||
import urllib3
|
||||
from urllib3.exceptions import ReadTimeoutError
|
||||
|
||||
from .base import Connection
|
||||
from ..exceptions import ConnectionError
|
||||
@@ -49,6 +50,9 @@ class Urllib3HttpConnection(Connection):
|
||||
response = self.pool.urlopen(method, url, body, retries=False, headers=self.headers, **kw)
|
||||
duration = time.time() - start
|
||||
raw_data = response.data.decode('utf-8')
|
||||
except ReadTimeoutError as e:
|
||||
self.log_request_fail(method, full_url, body, time.time() - start, exception=e)
|
||||
raise ConnectionError('TIMEOUT', str(e), e)
|
||||
except Exception as e:
|
||||
self.log_request_fail(method, full_url, body, time.time() - start, exception=e)
|
||||
raise ConnectionError('N/A', str(e), e)
|
||||
|
||||
@@ -14,7 +14,7 @@ try:
|
||||
except ImportError:
|
||||
THRIFT_AVAILABLE = False
|
||||
|
||||
from ..exceptions import ConnectionError, ImproperlyConfigured
|
||||
from ..exceptions import ConnectionError, ImproperlyConfigured, ConnectionTimeout
|
||||
from .pooling import PoolingConnection
|
||||
|
||||
logger = logging.getLogger('elasticsearch')
|
||||
@@ -66,6 +66,9 @@ class ThriftConnection(PoolingConnection):
|
||||
tclient = self._get_connection()
|
||||
response = tclient.execute(request)
|
||||
duration = time.time() - start
|
||||
except SocketTimeout as e:
|
||||
self.log_request_fail(method, url, body, time.time() - start, exception=e)
|
||||
raise ConnectionTimeout('TIMEOUT', str(e), e)
|
||||
except (TException, SocketTimeout) as e:
|
||||
self.log_request_fail(method, url, body, time.time() - start, exception=e)
|
||||
if tclient:
|
||||
|
||||
@@ -61,6 +61,13 @@ class ConnectionError(TransportError):
|
||||
self.error, self.info.__class__.__name__, self.info)
|
||||
|
||||
|
||||
class ConnectionTimeout(ConnectionError):
|
||||
""" A network timeout. """
|
||||
def __str__(self):
|
||||
return 'ConnectionTimeout caused by - %s(%s)' % (
|
||||
self.info.__class__.__name__, self.info)
|
||||
|
||||
|
||||
class NotFoundError(TransportError):
|
||||
""" Exception representing a 404 status code. """
|
||||
|
||||
|
||||
Reference in New Issue
Block a user