Skip to content

Instantly share code, notes, and snippets.

@pgolding
Created December 12, 2017 17:13
Show Gist options
  • Save pgolding/f43ab4dc29d329f74375f46b1b328139 to your computer and use it in GitHub Desktop.
Save pgolding/f43ab4dc29d329f74375f46b1b328139 to your computer and use it in GitHub Desktop.
The unclearly documented error exceptions of Boto3 (Python) DynamoDB - e.g. ConditionalCheckFailedException
from botocore import exceptions
try:
# to update table conditionally
except exceptions.ClientError as e:
if e.response['Error']['Code'] == 'ConditionalCheckFailedException':
print("ConditionalCheckFailedException detected")
# do something else, like raise a custom error based on the condition
raise DocDoesNotExistError("dang it!")
# Possible custom error response
class DocDoesNotExistError(Exception):
"""Generic exception class for API _errors_"""
def __init__(self, msg, original_exception=None):
if original_exception:
self.message = "DocDoesNotExistError: " + msg + (": %s" % original_exception)
else:
self.message = "DocDoesNotExistError: " + msg
super(DocDoesNotExistError, self).__init__(self.message)
self.original_exception = original_exception
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment