Source code for spotify.errors

__all__ = ("SpotifyException", "HTTPException", "Forbidden", "NotFound")


[docs]class SpotifyException(Exception): """Base exception class for spotify.py."""
[docs]class HTTPException(SpotifyException): """A generic exception that's thrown when a HTTP operation fails.""" def __init__(self, response, message): self.response = response self.status = response.status error = message.get("error") if isinstance(error, dict): self.text = error.get("message", "") else: self.text = message.get("error_description", "") fmt = "{0.reason} (status code: {0.status})" if self.text.strip(): fmt += ": {1}" super().__init__(fmt.format(self.response, self.text))
[docs]class Forbidden(HTTPException): """An exception that's thrown when status code 403 occurs."""
[docs]class NotFound(HTTPException): """An exception that's thrown when status code 404 occurs."""
class BearerTokenError(HTTPException): """An exception that's thrown when Spotify could not provide a valid Bearer Token""" class RateLimitedException(Exception): """An exception that gets thrown when a rate limit is encountered."""