"""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 OwsPaymentException(BaseOwsServiceException): """ows-payment exception.""" SERVICE = 'ows-payment' class OwsAccountException(BaseOwsServiceException): """ows-abacus-account exception.""" SERVICE = 'ows-abacus-account' class OwsEventException(BaseOwsServiceException): """ows-abacus-event exception.""" SERVICE = 'ows-abacus-event' class OwsLedgerException(BaseOwsServiceException): """ows-ledger exception.""" SERVICE = 'ows-ledger' class OwsRoyaltiesException(BaseOwsServiceException): """ows-royalties exception.""" SERVICE = 'ows-royalties'