"""Handle errors and raise exceptions.""" import abc import typing from config import app_logger as logger class BaseOwsServiceException(abc.ABC, Exception): """Custom exception when making ows service requests.""" def __init__(self, message: str, **kwargs: typing.Any): error_message = f'{self.SERVICE} failure: {message} {kwargs}' logger.error(error_message) super().__init__(error_message) @property @abc.abstractmethod def SERVICE(self) -> str: raise NotImplementedError() class OwsPayeeException(BaseOwsServiceException): """ows-payee exception.""" SERVICE = 'ows-payee' class OwsAbacusStateException(BaseOwsServiceException): """ows-abacus-state exception.""" SERVICE = 'ows-abacus-state' class OwsAbacusAccountException(BaseOwsServiceException): """ows-abacus-account exception.""" SERVICE = 'ows-abacus-account' class LogicError(Exception): """Custom exception for logic errors."""