mirror of
https://github.com/sprockets/sprockets.clients.dynamodb.git
synced 2024-11-23 11:19:54 +00:00
Handle gaierror and ConnectionError
This commit is contained in:
parent
aadb8f7a10
commit
33adf14265
4 changed files with 28 additions and 1 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
|
||||
|
@ -126,6 +127,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,5 +1,6 @@
|
|||
import datetime
|
||||
import os
|
||||
import socket
|
||||
import uuid
|
||||
|
||||
import mock
|
||||
|
@ -103,6 +104,21 @@ 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())
|
||||
|
||||
|
||||
@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