Handle more exception types

This commit is contained in:
Gavin M. Roy 2016-09-23 15:28:56 -04:00
parent c2c26da23b
commit a3f095553c
2 changed files with 11 additions and 2 deletions

View file

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

View file

@ -1,7 +1,9 @@
import json import json
import logging import logging
import os import os
import select
import socket import socket
import ssl
from tornado import concurrent, httpclient, ioloop from tornado import concurrent, httpclient, ioloop
import tornado_aws import tornado_aws
@ -10,7 +12,7 @@ from tornado_aws import exceptions as aws_exceptions
from . import utils from . import utils
from . import exceptions from . import exceptions
# Stub ConnectionError && ConnectionResetError for Python 2.7 # Stub Python3 exceptions for Python 2.7
try: try:
ConnectionError ConnectionError
except NameError: except NameError:
@ -20,6 +22,9 @@ except NameError:
class ConnectionResetError(Exception): class ConnectionResetError(Exception):
pass pass
class TimeoutError(Exception):
pass
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
@ -121,6 +126,8 @@ class DynamoDB(object):
response_reason = http_err.response.body response_reason = http_err.response.body
future.set_exception( future.set_exception(
exceptions.RequestException(response_reason)) exceptions.RequestException(response_reason))
except TimeoutError:
future.set_exception(exceptions.TimeoutException())
except Exception as exception: except Exception as exception:
future.set_exception(exception) future.set_exception(exception)
else: else:
@ -140,6 +147,8 @@ class DynamoDB(object):
except (ConnectionError, except (ConnectionError,
ConnectionResetError, ConnectionResetError,
OSError, OSError,
select.error,
ssl.socket_error,
socket.gaierror) as error: socket.gaierror) as error:
future.set_exception(exceptions.RequestException(str(error))) future.set_exception(exceptions.RequestException(str(error)))
except httpclient.HTTPError as err: except httpclient.HTTPError as err: