Handle OSError and ConnectionResetError

This commit is contained in:
Gavin M. Roy 2016-06-23 09:32:12 -04:00
parent 5471a14b11
commit e5e87e18f8
3 changed files with 26 additions and 5 deletions

View file

@ -4,7 +4,7 @@ except ImportError as error:
def DynamoDB(*args, **kwargs):
raise error
version_info = (0, 2, 2)
version_info = (0, 2, 3)
__version__ = '.'.join(str(v) for v in version_info)
# Response constants

View file

@ -10,13 +10,16 @@ from tornado_aws import exceptions as aws_exceptions
from . import utils
from . import exceptions
# Stub ConnectionError for Python 2.7 that doesn't support it
# Stub ConnectionError && ConnectionResetError for Python 2.7
try:
ConnectionError
except NameError:
class ConnectionError(Exception):
pass
class ConnectionResetError(Exception):
pass
LOGGER = logging.getLogger(__name__)
@ -134,8 +137,11 @@ class DynamoDB(object):
future.set_exception(exceptions.NoCredentialsError(str(error)))
except aws_exceptions.NoProfileError as error:
future.set_exception(exceptions.NoProfileError(str(error)))
except (socket.gaierror, ConnectionError) as req_err:
future.set_exception(exceptions.RequestException(req_err))
except (ConnectionError,
ConnectionResetError,
OSError,
socket.gaierror) as error:
future.set_exception(exceptions.RequestException(str(error)))
except httpclient.HTTPError as err:
if err.code == 599:
future.set_exception(exceptions.TimeoutException())

View file

@ -13,7 +13,7 @@ from tornado import testing
from tornado_aws import exceptions as aws_exceptions
from sprockets.clients import dynamodb
from sprockets.clients.dynamodb import connector, exceptions
from sprockets.clients.dynamodb import exceptions
class AsyncTestCase(testing.AsyncTestCase):
@ -113,6 +113,13 @@ class AWSClientTests(AsyncTestCase):
with self.assertRaises(exceptions.RequestException):
yield self.client.create_table(self.generic_table_definition())
@testing.gen_test
def test_oserror_raises_request_exception(self):
with mock.patch('tornado_aws.client.AsyncAWSClient.fetch') as fetch:
fetch.side_effect = OSError
with self.assertRaises(exceptions.RequestException):
yield self.client.create_table(self.generic_table_definition())
@unittest.skipIf(sys.version_info.major < 3,
'ConnectionError is Python3 only')
@testing.gen_test
@ -122,6 +129,14 @@ class AWSClientTests(AsyncTestCase):
with self.assertRaises(exceptions.RequestException):
yield self.client.create_table(self.generic_table_definition())
@unittest.skipIf(sys.version_info.major < 3,
'ConnectionResetError is Python3 only')
@testing.gen_test
def test_connection_reset_error_request_exception(self):
with mock.patch('tornado_aws.client.AsyncAWSClient.fetch') as fetch:
fetch.side_effect = ConnectionResetError
with self.assertRaises(exceptions.RequestException):
yield self.client.create_table(self.generic_table_definition())
class CreateTableTests(AsyncTestCase):