# app/exceptions/content_page.py """ Content Page Domain Exceptions These exceptions are raised by the content page service layer and converted to HTTP responses by the global exception handler. """ from app.exceptions.base import ( AuthorizationException, BusinessLogicException, ConflictException, ResourceNotFoundException, ValidationException, ) class ContentPageNotFoundException(ResourceNotFoundException): """Raised when a content page is not found.""" def __init__(self, identifier: str | int | None = None): if identifier: message = f"Content page not found: {identifier}" else: message = "Content page not found" super().__init__(message=message, resource_type="content_page") class ContentPageAlreadyExistsException(ConflictException): """Raised when a content page with the same slug already exists.""" def __init__(self, slug: str, vendor_id: int | None = None): if vendor_id: message = f"Content page with slug '{slug}' already exists for this vendor" else: message = f"Platform content page with slug '{slug}' already exists" super().__init__(message=message) class ContentPageSlugReservedException(ValidationException): """Raised when trying to use a reserved slug.""" def __init__(self, slug: str): super().__init__( message=f"Content page slug '{slug}' is reserved", field="slug", value=slug, ) class ContentPageNotPublishedException(BusinessLogicException): """Raised when trying to access an unpublished content page.""" def __init__(self, slug: str): super().__init__(message=f"Content page '{slug}' is not published") class UnauthorizedContentPageAccessException(AuthorizationException): """Raised when a user tries to access/modify a content page they don't own.""" def __init__(self, action: str = "access"): super().__init__( message=f"Cannot {action} content pages from other vendors", required_permission=f"content_page:{action}", ) class VendorNotAssociatedException(AuthorizationException): """Raised when a user is not associated with a vendor.""" def __init__(self): super().__init__( message="User is not associated with a vendor", required_permission="vendor:member", ) class ContentPageValidationException(ValidationException): """Raised when content page data validation fails.""" def __init__(self, field: str, message: str, value: str | None = None): super().__init__(message=message, field=field, value=value)