"""Exception types used across the package.""" from __future__ import annotations class StickerDownloaderError(Exception): """Base class for every error raised by this package.""" class InvalidPackReference(StickerDownloaderError): """Raised when a string cannot be read as a sticker pack reference.""" class InvalidFileType(StickerDownloaderError): """Raised when the user asks for a file type we cannot download.""" class FetchError(StickerDownloaderError): """Raised when the CDN returns a non-success status for a file.""" def __init__(self, url: str, status: int, reason: str = "") -> None: detail = f" ({reason})" if reason else "" super().__init__(f"HTTP {status}{detail} for {url}") self.url = url self.status = status self.reason = reason @property def retriable(self) -> bool: """Rate limits and server-side faults are worth another attempt.""" return self.status == 429 or self.status >= 500