"""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.""" error_code: str | None additional_data: dict[str, typing.Any] | None = None def __init__( self, message: str, error_code: str | None = None, additional_data: dict[str, typing.Any] | None = None, **kwargs: typing.Any, ): """Init the class.""" if kwargs: error_message = f'{self.SERVICE} failure: {message} {kwargs}' else: error_message = f'{self.SERVICE} failure: {message}' if not error_code: logger.error(error_message) super().__init__(error_message) self.additional_data = additional_data self.error_code = error_code @property @abc.abstractmethod def SERVICE(self) -> str: """Service name stub.""" raise NotImplementedError() class OwsPayeeException(BaseOwsServiceException): """ows-payee exception.""" SERVICE = 'ows-payee' class OwsAbacusStateException(BaseOwsServiceException): """ows-abacus-state exception.""" SERVICE = 'ows-abacus-state' class OwsPaymentException(BaseOwsServiceException): """ows-payment exception.""" SERVICE = 'ows-payment' class OwsAbacusAccountException(BaseOwsServiceException): """ows-abacus-account exception.""" SERVICE = 'ows-abacus-account'