mirror of
https://github.com/sprockets/sprockets.clients.dynamodb.git
synced 2024-11-23 11:19:54 +00:00
Merge pull request #5 from sprockets/handle-more-errors
Handle gaierror and ConnectionError
This commit is contained in:
commit
5471a14b11
4 changed files with 39 additions and 2 deletions
|
@ -4,7 +4,7 @@ except ImportError as error:
|
|||
def DynamoDB(*args, **kwargs):
|
||||
raise error
|
||||
|
||||
version_info = (0, 2, 1)
|
||||
version_info = (0, 2, 2)
|
||||
__version__ = '.'.join(str(v) for v in version_info)
|
||||
|
||||
# Response constants
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import json
|
||||
import logging
|
||||
import os
|
||||
import socket
|
||||
|
||||
from tornado import concurrent, httpclient, ioloop
|
||||
import tornado_aws
|
||||
|
@ -9,6 +10,13 @@ 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
|
||||
try:
|
||||
ConnectionError
|
||||
except NameError:
|
||||
class ConnectionError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -126,6 +134,8 @@ 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 httpclient.HTTPError as err:
|
||||
if err.code == 599:
|
||||
future.set_exception(exceptions.TimeoutException())
|
||||
|
|
|
@ -17,6 +17,14 @@ class DynamoDBException(Exception):
|
|||
super(DynamoDBException, self).__init__(*args, **kwargs)
|
||||
|
||||
|
||||
class RequestException(DynamoDBException):
|
||||
"""Raised when the HTTP request failed due to a network or DNS related
|
||||
issue.
|
||||
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
class ConditionalCheckFailedException(DynamoDBException):
|
||||
"""A condition specified in the operation could not be evaluated."""
|
||||
pass
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
import datetime
|
||||
import os
|
||||
import socket
|
||||
import sys
|
||||
import uuid
|
||||
import unittest
|
||||
|
||||
import mock
|
||||
|
||||
|
@ -10,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 exceptions
|
||||
from sprockets.clients.dynamodb import connector, exceptions
|
||||
|
||||
|
||||
class AsyncTestCase(testing.AsyncTestCase):
|
||||
|
@ -103,6 +106,22 @@ class AWSClientTests(AsyncTestCase):
|
|||
with self.assertRaises(exceptions.DynamoDBException):
|
||||
yield self.client.create_table(self.generic_table_definition())
|
||||
|
||||
@testing.gen_test
|
||||
def test_gaierror_raises_request_exception(self):
|
||||
with mock.patch('tornado_aws.client.AsyncAWSClient.fetch') as fetch:
|
||||
fetch.side_effect = socket.gaierror
|
||||
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
|
||||
def test_connection_error_request_exception(self):
|
||||
with mock.patch('tornado_aws.client.AsyncAWSClient.fetch') as fetch:
|
||||
fetch.side_effect = ConnectionError
|
||||
with self.assertRaises(exceptions.RequestException):
|
||||
yield self.client.create_table(self.generic_table_definition())
|
||||
|
||||
|
||||
class CreateTableTests(AsyncTestCase):
|
||||
|
||||
|
|
Loading…
Reference in a new issue