dynamodb-mock / ddbmock / errors.py

# -*- coding: utf-8 -*-

class DDBError(Exception):
    def to_dict(self):
        name = type(self).__name__
        msg = self.args[0] if self.args else ""

        return {
            "__type": "com.amazonaws.dynamodb.v20111205#{}".format(name),
            "message": msg,
        }

class BadRequest(DDBError):  status=400; status_str='Bad Request'
class ServerError(DDBError): status=500; status_str='InternalServerError'

class AccessDeniedException(BadRequest): pass
class ConditionalCheckFailedException(BadRequest): pass
class IncompleteSignatureException(BadRequest): pass
class LimitExceededException(BadRequest): pass
class MissingAuthenticationTokenException(BadRequest): pass
class ProvisionedThroughputExceededException(BadRequest): pass
class ResourceInUseException(BadRequest): pass
class ResourceNotFoundException(BadRequest): pass
class ThrottlingException(BadRequest): pass
class ValidationException(BadRequest): pass
class InternalFailure(ServerError): pass
class InternalServerError(ServerError): pass
class ServiceUnavailableException(ServerError): pass

def wrap_exceptions(func):
    def wrapped(*args):
        try:
            return func(*args)
        except (TypeError, ValueError) as e:
            raise ValidationException(*e.args)
        except KeyError as e:
            raise InternalServerError(e.__name__, *e.args)
    return wrapped
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.