"""Handle errors and raise exceptions.""" import abc from http import HTTPStatus from typing import Any from aws_lambda_powertools.event_handler.exceptions import ServiceError from config import app_logger as logger class BaseOwsServiceException(ServiceError): """Custom exception when making ows service requests.""" def __init__( self, message: str, status_code: int = HTTPStatus.INTERNAL_SERVER_ERROR, **kwargs: Any, ): """Init the class.""" error_message = f'{self.SERVICE} failure: {message} {kwargs}' logger.error(error_message) super().__init__(status_code, error_message) @property @abc.abstractmethod def SERVICE(self) -> str: """Service name stub.""" raise NotImplementedError() class OwsPayeeException(BaseOwsServiceException): """ows-payee exception.""" SERVICE = 'ows-payee'