Source code for ourobori.services.errors

"""
This module contains all exceptions used in services based on the ourobori.
Additional service specific exceptions have to be defined in the
``errors.py``-file of the service and be defined in the service
``rules.py``-file in ``Rules.handle_exceptions``.
"""


import attr


[docs]@attr.s(auto_attribs=True, cmp=False) class BaseError(Exception): """ The base-exception all custom-exceptions have to inherit from. Attributes: status: This attribute has to be defined in an exception inheriting from this class. It represents the http-status-code to return to the client on raise of the exception. data: This attribute has to be defined in an exception inheriting from this class. It contains a dict with the message (``msg``) to return to the client on raise of the exception. Additional keys can be passed, too. description: The description for the exception. """ status: int = NotImplemented data: dict = NotImplemented description: str = NotImplemented
def prepare_exception_ctx(exception_class: BaseError, exception_params: dict) -> BaseError: """ Wrapper function to modify the attributes data and description of passed exception of base BaseClass with passed exception-params. Parameters: exception_class: The exception to modify the attributes data and description for. exception_params: Used to modify the data and description attributes of the passed exception Returns: exc: Instance of the passed exception_class with modified attributes data and description. """ _exc = exception_class() exc = exception_class( status=_exc.status, data=dict(msg=_exc.data['msg'].format(**exception_params)), description=_exc.description.format(**exception_params)) return exc
[docs]@attr.s(auto_attribs=True, cmp=False) class InvalidInputException(BaseError): """ This exception is used if invalid-input is passed to an api. .. admonition:: Inheritance .. inheritance-diagram:: InvalidInputException :top-classes: BaseError Attributes: status: It represents the http-status-code to return to the client on raise of the exception. data: It contains a dict with the message (``msg``) to return to the client on raise of the exception. description: The description for this exception. """ status: int = 412 data: dict = dict(msg='Invalid input data passed!') description: str = 'Invalid input data was passed to the api.'
[docs]@attr.s(auto_attribs=True, cmp=False) class InvalidOutputException(BaseError): """ This exception is used if the output created by the api is not valid. .. admonition:: Inheritance .. inheritance-diagram:: InvalidOutputException :top-classes: BaseError Attributes: status: It represents the http-status-code to return to the client on raise of the exception. data: It contains a dict with the message (``msg``) to return to the client on raise of the exception. description: The description for this exception. """ status: int = 500 data: dict = dict(msg='Please contact support') description: str = 'Invalid output created.'
[docs]@attr.s(auto_attribs=True, cmp=False) class ServiceCallException(BaseError): """ This exception is used inside the dependencies :class:`ourobori.apps.dependencies.services.RestService` .. admonition:: Inheritance .. inheritance-diagram:: ServiceCallException :top-classes: BaseError Attributes: status: It represents the http-status-code to return to the client on raise of the exception. data: It contains a dict with the message (``msg``) to return to the client on raise of the exception. description: The description for this exception. """ status: int = 501 data: dict = dict(msg=( 'Could not call service-dependency {name}. Please contact support')) description: str = ('Could not call service-dependency {name} ' 'on api {api} with params {params}. Err: {err}')
[docs]@attr.s(auto_attribs=True, cmp=False) class ServiceNotAliveException(BaseError): """ This exception is used inside the dependencies :class:`ourobori.apps.dependencies.services.RestService` .. admonition:: Inheritance .. inheritance-diagram:: ServiceNotAliveException :top-classes: BaseError Attributes: status: It represents the http-status-code to return to the client on raise of the exception. data: It contains a dict with the message (``msg``) to return to the client on raise of the exception. description: The description for this exception. """ status: int = 502 data: dict = dict(msg=( 'Service-dependency {name} is not alive. Please contact support')) description: str = 'Service-dependency {name} is not alive'
[docs]@attr.s(auto_attribs=True, cmp=False) class DatabaseNotAliveException(BaseError): """ This exception is used inside the dependencies :class:`ourobori.apps.dependencies.dbs.PSQLDataBase` .. admonition:: Inheritance .. inheritance-diagram:: DatabaseNotAliveException :top-classes: BaseError Attributes: status: It represents the http-status-code to return to the client on raise of the exception. data: It contains a dict with the message (``msg``) to return to the client on raise of the exception. description: The description for this exception. """ status: int = 503 data: dict = dict(msg=( 'Database {name} is not alive. Please contact support')) description: str = 'Database {name} at {dsn} is not alive'
[docs]@attr.s(auto_attribs=True, cmp=False) class DatabaseTransactionException(BaseError): """ This exception is used inside the dependencies :class:`ourobori.apps.dependencies.dbs.PSQLDataBase` .. admonition:: Inheritance .. inheritance-diagram:: DatabaseTransactionException :top-classes: BaseError Attributes: status: It represents the http-status-code to return to the client on raise of the exception. data: It contains a dict with the message (``msg``) to return to the client on raise of the exception. description: The description for this exception. """ status: int = 504 data: dict = dict(msg=( 'Database {name} transaction {transaction} not possible. ' 'Please contact support')) description: str = ('Database {name} transaction {transaction} not ' 'possible. Err: {err}')
[docs]@attr.s(auto_attribs=True, cmp=False) class HostCmdException(BaseError): """ This exception is used inside the dependencies :class:`ourobori.apps.dependencies.hosts.Host` .. admonition:: Inheritance .. inheritance-diagram:: HostCmdException :top-classes: BaseError Attributes: status: It represents the http-status-code to return to the client on raise of the exception. data: It contains a dict with the message (``msg``) to return to the client on raise of the exception. description: The description for this exception. """ status: int = 505 data: dict = dict(msg=( 'Host {name} running command {cmd} not possible. ' 'Please contact support')) description: str = ('Host {name} running command {cmd} not possible. ' 'Err: {err}')
[docs]@attr.s(auto_attribs=True, cmp=False) class HostSCPFromException(BaseError): """ This exception is used inside the dependencies :class:`ourobori.apps.dependencies.hosts.Host` .. admonition:: Inheritance .. inheritance-diagram:: HostSCPFromException :top-classes: BaseError Attributes: status: It represents the http-status-code to return to the client on raise of the exception. data: It contains a dict with the message (``msg``) to return to the client on raise of the exception. description: The description for this exception. """ status: int = 506 data: dict = dict(msg=( 'Host {name} copying from is not possible. Please contact support')) description: str = 'Host {name} copying from is not possible. Er: {err}'
[docs]@attr.s(auto_attribs=True, cmp=False) class HostSCPToException(BaseError): """ This exception is used inside the dependencies :class:`ourobori.apps.dependencies.hosts.Host` .. admonition:: Inheritance .. inheritance-diagram:: HostSCPToException :top-classes: BaseError Attributes: status: It represents the http-status-code to return to the client on raise of the exception. data: It contains a dict with the message (``msg``) to return to the client on raise of the exception. description: The description for this exception. """ status: int = 507 data: dict = dict(msg=( 'Host {name} copying to is not possible. Please contact support')) description: str = 'Host {name} copying to is not possible. Err: {err}'
[docs]@attr.s(auto_attribs=True, cmp=False) class HostConnectionException(BaseError): """ This exception is used inside the dependencies :class:`ourobori.apps.dependencies.hosts.Host` .. admonition:: Inheritance .. inheritance-diagram:: HostConnectionException :top-classes: BaseError Attributes: status: It represents the http-status-code to return to the client on raise of the exception. data: It contains a dict with the message (``msg``) to return to the client on raise of the exception. description: The description for this exception. """ status: int = 508 data: dict = dict(msg=( 'Host {name} connecting to is not possible. Please contact support')) description: str = ('Host {name} connecting to is not possible. ' 'Err: {err}')
__all__ = ['BaseError', 'DatabaseNotAliveException', 'DatabaseTransactionException', 'HostCmdException', 'HostConnectionException', 'HostSCPFromException', 'HostSCPToException', 'InvalidInputException', 'InvalidOutputException', 'ServiceCallException', 'ServiceNotAliveException', ]