mirror of
https://github.com/sprockets/sprockets.clients.dynamodb.git
synced 2024-11-23 11:19:54 +00:00
Merge pull request #6 from sprockets/new-exceptions
Handle OSError and ConnectionResetError
This commit is contained in:
commit
fc23a521b5
3 changed files with 26 additions and 5 deletions
|
@ -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
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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):
|
||||
|
||||
|
|
Loading…
Reference in a new issue