Handle library errors using the SpotifyScraperError hierarchy
masterAll errors raised by the library derive from a single base class: SpotifyScraperError. To catch any error produced by the library, you should catch this base exception.
Specific error subtypes include:
URLError: Raised when input is not a valid Spotify URL, URI, or ID.NetworkError: Raised during transport failures (wraps underlyinghttpxerrors).RateLimitedError: A subtype ofNetworkErrorthat includes aretry_after: float | Noneattribute to indicate how long to wait before retrying.TokenError: Raised when anonymous token bootstrapping or refreshing fails.AuthenticationError: Raised when user credentials are missing or expired for authenticated features.NotFoundError: Raised when an entity does not exist or is unavailable.ParsingError: Raised if the Spotify payload shape has changed.MediaError: Raised during download or tagging failures.
try:
# Perform SpotifyScraper operation
pass
except SpotifyScraperError as e:
# This catches all library-specific errors
print(f"An error occurred: {e}")
except RateLimitedError as e:
# Specific handling for rate limits
if e.retry_after:
print(f"Retrying after {e.retry_after} seconds")