"""Exceptions.""" from typing import Any from werkzeug.exceptions import ( BadRequest, Forbidden, InternalServerError, NotFound, Unauthorized, ) class _ErrorCodeMixin: """Mixin that allows error_code to be overridden at raise time.""" def __init__( self, description: str | None = None, error_code: str | None = None, **kwargs: Any, ) -> None: super().__init__(description, **kwargs) # type: ignore[call-arg] if error_code is not None: self.error_code = error_code class InvalidRequest(_ErrorCodeMixin, BadRequest): """Raised when a request is malformed or contains invalid data.""" description = "bad request" class OARequired(_ErrorCodeMixin, Unauthorized): """Raised when a request requires an OA user.""" error_code = "UNAUTHORIZED" description = "Must be oa" class VideoValidationError(BadRequest): """Raised when video product validation fails with a list of error codes.""" error_code = "validation_error" def __init__(self, errors: Any) -> None: super().__init__(description=errors) self.validation_errors = errors class InvalidReleaseStatus(_ErrorCodeMixin, BadRequest): """Raised when a release is not in the required status to take an action.""" error_code = "invalid_release_status" description = "Invalid release status" class ApprovalNotFound(_ErrorCodeMixin, NotFound): """Raised when an approval is not found.""" description = "approval not found" class AutoCarveoutNotFound(_ErrorCodeMixin, NotFound): """Raised when an auto carveout is not found.""" description = "auto carveout not found" class ProductManagerNotFound(_ErrorCodeMixin, NotFound): """Raised when a product manager mapping is not found.""" description = "product manager not found" class ProductVideoNotFound(_ErrorCodeMixin, NotFound): """Raised when a product video is not found.""" description = "product video not found" class ProductVideoSizingRuleNotFound(_ErrorCodeMixin, NotFound): """Raised when a product video sizing rule is not found.""" description = "product video sizing rule not found" class ReleaseNotFound(_ErrorCodeMixin, NotFound): """Raised when a release is not found.""" description = "release not found" class VideoAssetNotFound(_ErrorCodeMixin, NotFound): """Raised when a video asset is not found.""" description = "video asset not found" class VideoTypeNotFound(_ErrorCodeMixin, NotFound): """Raised when a video type is not found.""" description = "video type not found" class TrackNotFound(_ErrorCodeMixin, NotFound): """Raised when a track is not found.""" description = "track not found" class JobNotFound(_ErrorCodeMixin, NotFound): """Raised when a job is not found.""" description = "job not found" class ArtistNotFound(_ErrorCodeMixin, NotFound): """Raised when an artist is not found.""" description = "artist not found" class SubaccountNotFound(_ErrorCodeMixin, NotFound): """Raised when a subaccount is not found.""" description = "subaccount not found" class SubmissionNotAllowed(Forbidden): """Raised when a product is not valid and cannot be submitted.""" description = "" class AccessForbidden(_ErrorCodeMixin, Forbidden): """Raised when the requesting account does not have access.""" error_code = "authorization_error" description = "access forbidden" class ArtistOwnershipError(_ErrorCodeMixin, Forbidden): """Raised when the requesting account does not own the artist.""" description = "artist ownership verification failed" class ProductOwnershipError(_ErrorCodeMixin, Forbidden): """Raised when the requesting account does not own the product.""" description = "product ownership verification failed" class ProjectNotFound(_ErrorCodeMixin, NotFound): """Raised when a project is not found.""" description = "project not found" class ProjectOwnershipError(_ErrorCodeMixin, Forbidden): """Raised when the requesting account does not own the project.""" description = "project ownership verification failed" class ProductVideoDataError(_ErrorCodeMixin, InternalServerError): """Raised when product video data is in an unexpected state.""" description = "product video data error"