Created
December 12, 2017 17:13
-
-
Save pgolding/f43ab4dc29d329f74375f46b1b328139 to your computer and use it in GitHub Desktop.
The unclearly documented error exceptions of Boto3 (Python) DynamoDB - e.g. ConditionalCheckFailedException
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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