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):
|
def DynamoDB(*args, **kwargs):
|
||||||
raise error
|
raise error
|
||||||
|
|
||||||
version_info = (0, 2, 2)
|
version_info = (0, 2, 3)
|
||||||
__version__ = '.'.join(str(v) for v in version_info)
|
__version__ = '.'.join(str(v) for v in version_info)
|
||||||
|
|
||||||
# Response constants
|
# Response constants
|
||||||
|
|
|
@ -10,13 +10,16 @@ from tornado_aws import exceptions as aws_exceptions
|
||||||
from . import utils
|
from . import utils
|
||||||
from . import exceptions
|
from . import exceptions
|
||||||
|
|
||||||
# Stub ConnectionError for Python 2.7 that doesn't support it
|
# Stub ConnectionError && ConnectionResetError for Python 2.7
|
||||||
try:
|
try:
|
||||||
ConnectionError
|
ConnectionError
|
||||||
except NameError:
|
except NameError:
|
||||||
class ConnectionError(Exception):
|
class ConnectionError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
class ConnectionResetError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
LOGGER = logging.getLogger(__name__)
|
LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -134,8 +137,11 @@ class DynamoDB(object):
|
||||||
future.set_exception(exceptions.NoCredentialsError(str(error)))
|
future.set_exception(exceptions.NoCredentialsError(str(error)))
|
||||||
except aws_exceptions.NoProfileError as error:
|
except aws_exceptions.NoProfileError as error:
|
||||||
future.set_exception(exceptions.NoProfileError(str(error)))
|
future.set_exception(exceptions.NoProfileError(str(error)))
|
||||||
except (socket.gaierror, ConnectionError) as req_err:
|
except (ConnectionError,
|
||||||
future.set_exception(exceptions.RequestException(req_err))
|
ConnectionResetError,
|
||||||
|
OSError,
|
||||||
|
socket.gaierror) as error:
|
||||||
|
future.set_exception(exceptions.RequestException(str(error)))
|
||||||
except httpclient.HTTPError as err:
|
except httpclient.HTTPError as err:
|
||||||
if err.code == 599:
|
if err.code == 599:
|
||||||
future.set_exception(exceptions.TimeoutException())
|
future.set_exception(exceptions.TimeoutException())
|
||||||
|
|
|
@ -13,7 +13,7 @@ from tornado import testing
|
||||||
from tornado_aws import exceptions as aws_exceptions
|
from tornado_aws import exceptions as aws_exceptions
|
||||||
|
|
||||||
from sprockets.clients import dynamodb
|
from sprockets.clients import dynamodb
|
||||||
from sprockets.clients.dynamodb import connector, exceptions
|
from sprockets.clients.dynamodb import exceptions
|
||||||
|
|
||||||
|
|
||||||
class AsyncTestCase(testing.AsyncTestCase):
|
class AsyncTestCase(testing.AsyncTestCase):
|
||||||
|
@ -113,6 +113,13 @@ class AWSClientTests(AsyncTestCase):
|
||||||
with self.assertRaises(exceptions.RequestException):
|
with self.assertRaises(exceptions.RequestException):
|
||||||
yield self.client.create_table(self.generic_table_definition())
|
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,
|
@unittest.skipIf(sys.version_info.major < 3,
|
||||||
'ConnectionError is Python3 only')
|
'ConnectionError is Python3 only')
|
||||||
@testing.gen_test
|
@testing.gen_test
|
||||||
|
@ -122,6 +129,14 @@ class AWSClientTests(AsyncTestCase):
|
||||||
with self.assertRaises(exceptions.RequestException):
|
with self.assertRaises(exceptions.RequestException):
|
||||||
yield self.client.create_table(self.generic_table_definition())
|
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):
|
class CreateTableTests(AsyncTestCase):
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue