Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Making DynamoDBResponseError behave more like standard XML-based erro…

…rs. Closes #625.
  • Loading branch information...
commit 9e7b06e0ffa0819342760cefd9d50cd8bdf7396e 1 parent 9a14f7b
@garnaat garnaat authored
View
8 boto/dynamodb/layer1.py
@@ -135,8 +135,8 @@ def _retry_handler(self, response, i, next_sleep):
if response.status == 400:
response_body = response.read()
boto.log.debug(response_body)
- json_response = json.loads(response_body)
- if self.ThruputError in json_response.get('__type'):
+ data = json.loads(response_body)
+ if self.ThruputError in data.get('__type'):
self.throughput_exceeded_events += 1
msg = "%s, retry attempt %s" % (self.ThruputError, i)
if i == 0:
@@ -145,14 +145,14 @@ def _retry_handler(self, response, i, next_sleep):
next_sleep = 0.05 * (2**i)
i += 1
status = (msg, i, next_sleep)
- elif self.SessionExpiredError in json_response.get('__type'):
+ elif self.SessionExpiredError in data.get('__type'):
msg = 'Renewing Session Token'
self.creds = self._get_session_token()
self._update_provider()
status = (msg, i+self.num_retries-1, next_sleep)
else:
raise self.ResponseError(response.status, response.reason,
- json_response)
+ data)
return status
def list_tables(self, limit=None, start_table=None):
View
25 boto/exception.py
@@ -299,11 +299,28 @@ def _cleanupParsedProperties(self):
setattr(self, p, None)
class DynamoDBResponseError(BotoServerError):
+ """
+ This exception expects the fully parsed and decoded JSON response
+ body to be passed as the body parameter.
+
+ :ivar status: The HTTP status code.
+ :ivar reason: The HTTP reason message.
+ :ivar body: The Python dict that represents the decoded JSON
+ response body.
+ :ivar error_message: The full description of the AWS error encountered.
+ :ivar error_code: A short string that identifies the AWS error
+ (e.g. ConditionalCheckFailedException)
+ """
- def __init__(self, status, reason, data):
- BotoServerError.__init__(self, status, reason)
- self.data = data
- self.body = '%s' % self.data
+ def __init__(self, status, reason, body=None, *args):
+ self.status = status
+ self.reason = reason
+ self.body = body
+ if self.body:
+ self.error_message = self.body.get('message', None)
+ self.error_code = self.body.get('__type', None)
+ if self.error_code:
+ self.error_code = self.error_code.split('#')[-1]
class EmrResponseError(BotoServerError):
"""
View
4 tests/dynamodb/test_layer1.py
@@ -135,9 +135,9 @@ def test_layer1_basic(self):
# Try to delete the item with the wrong Expected value
expected = {'Views': {'Value': {'N': '1'}}}
try:
- result = c.delete_item('table_name', key=key1, expected=expected)
+ result = c.delete_item(table_name, key=key1, expected=expected)
except c.ResponseError, e:
- pass
+ assert e.error_code == 'ConditionalCheckFailedException'
# Now update the existing object
attribute_updates = {'Views': {'Value': {'N': '5'},
View
2  tests/dynamodb/test_layer2.py
@@ -140,7 +140,7 @@ def test_layer2_basic(self):
try:
item1.delete(expected_value=expected)
except c.layer1.ResponseError, e:
- pass
+ assert e.error_code == 'ConditionalCheckFailedException'
else:
raise Exception("Expected Value condition failed")
Please sign in to comment.
Something went wrong with that request. Please try again.