1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
class DiscogsAPIError(Exception):
"""Root Exception class for Discogs API errors."""
pass
class TooManyAttemptsError(DiscogsAPIError):
"""
Exception class for when the ratelimit for the API is hit too many times
consecutively and backing off has not helped.
"""
def __init__(self):
self.msg = (
"Failed to make request due to the API "
"returning 429, rate limited response, consecutively too many times. "
"Back off function has not helped."
)
def __str__(self):
return self.msg
class ConfigurationError(DiscogsAPIError):
"""Exception class for problems with the configuration of this client."""
def __init__(self, msg):
self.msg = msg
def __str__(self):
return self.msg
class HTTPError(DiscogsAPIError):
"""Exception class for HTTP errors."""
def __init__(self, message, code):
self.status_code = code
self.msg = '{0}: {1}'.format(code, message)
def __str__(self):
return self.msg
class AuthorizationError(HTTPError):
"""The server rejected the client's credentials."""
def __init__(self, message, code, response):
super(AuthorizationError, self).__init__(message, code)
self.msg = '{0} Response: {1!r}'.format(self.msg, response)
|