"""Custom exceptions for Smarter API Manifest handling."""
import re
from smarter.common.exceptions import SmarterException
[docs]
class SAMExceptionBase(SmarterException):
"""Base exception for Smarter API Manifest handling."""
@property
def get_formatted_err_message(self) -> str:
"""The class name as words, e.g. ``Smarter API Manifest validation error`` for ``SAMValidationError``."""
name = self.__class__.__name__
name = name.replace("SAM", "Smarter API Manifest ")
words = re.findall("[A-Z][^A-Z]*", name)
retval = " ".join(str(word).lower() for word in words)
retval = retval.replace("smarter a p i manifest", "Smarter API Manifest")
retval = retval.replace(" ", " ")
return retval
[docs]
class SAMBadRequestError(SAMExceptionBase):
"""Exception raised when handling http requests."""
[docs]
class SAMValidationError(SAMExceptionBase):
"""Exception raised when a manifest, or a value in it, is invalid."""