Source code for drowsy.exc
"""
drowsy.exc
~~~~~~~~~~
Exceptions for Drowsy.
"""
# :copyright: (c) 2016-2020 by Nicholas Repole and contributors.
# See AUTHORS for more details.
# :license: MIT - See LICENSE for more details.
from marshmallow.exceptions import ValidationError
MISSING_ERROR_MESSAGE = (
"An error was raised by `{class_name}` with the key `{key}`, "
"but no such key exists in the `error_messages` dictionary."
)
[docs]
class DrowsyError(Exception):
"""Exception that contains a simple message attribute."""
[docs]
def __init__(self, code, message, **kwargs):
"""Initializes a new error.
:param str code: Error code for easier lookup.
:param str message: Description of the error.
:param dict kwargs: Any additional arguments may be stored along
with the message as well.
"""
self.code = code
self.message = message
self.kwargs = kwargs
super(DrowsyError, self).__init__()
[docs]
class UnprocessableEntityError(DrowsyError):
"""Exception for when provided data is unable to be deserialized."""
[docs]
def __init__(self, code, message, errors, **kwargs):
"""Initializes a new unprocessable entity error.
:param str code: Error code for easier lookup.
:param str message: Description of the error.
:param dict errors: A field by field breakdown of errors.
:param dict kwargs: Any additional arguments may be stored along
with the message and errors as well.
"""
self.errors = errors
super(UnprocessableEntityError, self).__init__(code, message, **kwargs)
[docs]
class PermissionDeniedError(DrowsyError):
"""Exception for when provided data is unable to be deserialized."""
[docs]
def __init__(self, code, message, errors, **kwargs):
"""Initializes a new permission denied error.
:param str code: Error code for easier lookup.
:param str message: Description of the error.
:param dict errors: A field by field breakdown of errors.
:param dict kwargs: Any additional arguments may be stored along
with the message and errors as well.
"""
self.errors = errors
super(PermissionDeniedError, self).__init__(code, message, **kwargs)
[docs]
class BadRequestError(DrowsyError):
"""Exception for when a request is unable to be processed."""
pass
[docs]
class MethodNotAllowedError(DrowsyError):
"""Error for when a request is made with an unsupported method."""
pass
[docs]
class ResourceNotFoundError(DrowsyError):
"""Exception for when a requested resource cannot be found."""
pass
[docs]
class ParseError(DrowsyError):
"""Generic exception class for parsing errors."""
pass
[docs]
class OffsetLimitParseError(ParseError):
"""Generic exception class for offset or limit parsing errors."""
pass
[docs]
class FilterParseError(ParseError):
"""Generic exception class for filter parsing errors."""
pass
[docs]
class PermissionValidationError(ValidationError):
"""Generic schema exception class for an unauthorized action."""
pass