mirror of
https://github.com/spotipy-dev/spotipy.git
synced 2026-06-19 09:13:53 +00:00
created SpotifyBaseException and moved exceptions from oauth2.py to exceptions.py (#1161)
This commit is contained in:
parent
d9da5af53c
commit
db3fb9a5ee
@ -18,6 +18,7 @@ Add your changes below.
|
|||||||
- Added custom `urllib3.Retry` class for printing a warning when a rate/request limit is reached.
|
- Added custom `urllib3.Retry` class for printing a warning when a rate/request limit is reached.
|
||||||
- Added `personalized_playlist.py`, `track_recommendations.py`, and `audio_features_analysis.py` to `/examples`.
|
- Added `personalized_playlist.py`, `track_recommendations.py`, and `audio_features_analysis.py` to `/examples`.
|
||||||
- Discord badge in README
|
- Discord badge in README
|
||||||
|
- Added `SpotifyBaseException` and moved all exceptions to `exceptions.py`
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- Audiobook integration tests
|
- Audiobook integration tests
|
||||||
|
|||||||
@ -1,4 +1,8 @@
|
|||||||
class SpotifyException(Exception):
|
class SpotifyBaseException(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class SpotifyException(SpotifyBaseException):
|
||||||
|
|
||||||
def __init__(self, http_status, code, msg, reason=None, headers=None):
|
def __init__(self, http_status, code, msg, reason=None, headers=None):
|
||||||
self.http_status = http_status
|
self.http_status = http_status
|
||||||
@ -14,3 +18,26 @@ class SpotifyException(Exception):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return 'http status: {}, code:{} - {}, reason: {}'.format(
|
return 'http status: {}, code:{} - {}, reason: {}'.format(
|
||||||
self.http_status, self.code, self.msg, self.reason)
|
self.http_status, self.code, self.msg, self.reason)
|
||||||
|
|
||||||
|
|
||||||
|
class SpotifyOauthError(SpotifyBaseException):
|
||||||
|
""" Error during Auth Code or Implicit Grant flow """
|
||||||
|
|
||||||
|
def __init__(self, message, error=None, error_description=None, *args, **kwargs):
|
||||||
|
self.error = error
|
||||||
|
self.error_description = error_description
|
||||||
|
self.__dict__.update(kwargs)
|
||||||
|
super().__init__(message, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
class SpotifyStateError(SpotifyOauthError):
|
||||||
|
""" The state sent and state received were different """
|
||||||
|
|
||||||
|
def __init__(self, local_state=None, remote_state=None, message=None,
|
||||||
|
error=None, error_description=None, *args, **kwargs):
|
||||||
|
if not message:
|
||||||
|
message = ("Expected " + local_state + " but received "
|
||||||
|
+ remote_state)
|
||||||
|
super(SpotifyOauthError, self).__init__(message, error,
|
||||||
|
error_description, *args,
|
||||||
|
**kwargs)
|
||||||
|
|||||||
@ -20,34 +20,12 @@ from http.server import BaseHTTPRequestHandler, HTTPServer
|
|||||||
from urllib.parse import parse_qsl, urlparse
|
from urllib.parse import parse_qsl, urlparse
|
||||||
|
|
||||||
from spotipy.cache_handler import CacheFileHandler, CacheHandler
|
from spotipy.cache_handler import CacheFileHandler, CacheHandler
|
||||||
|
from spotipy.exceptions import SpotifyOauthError, SpotifyStateError
|
||||||
from spotipy.util import CLIENT_CREDS_ENV_VARS, get_host_port, normalize_scope
|
from spotipy.util import CLIENT_CREDS_ENV_VARS, get_host_port, normalize_scope
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class SpotifyOauthError(Exception):
|
|
||||||
""" Error during Auth Code or Implicit Grant flow """
|
|
||||||
|
|
||||||
def __init__(self, message, error=None, error_description=None, *args, **kwargs):
|
|
||||||
self.error = error
|
|
||||||
self.error_description = error_description
|
|
||||||
self.__dict__.update(kwargs)
|
|
||||||
super().__init__(message, *args, **kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
class SpotifyStateError(SpotifyOauthError):
|
|
||||||
""" The state sent and state received were different """
|
|
||||||
|
|
||||||
def __init__(self, local_state=None, remote_state=None, message=None,
|
|
||||||
error=None, error_description=None, *args, **kwargs):
|
|
||||||
if not message:
|
|
||||||
message = ("Expected " + local_state + " but received "
|
|
||||||
+ remote_state)
|
|
||||||
super(SpotifyOauthError, self).__init__(message, error,
|
|
||||||
error_description, *args,
|
|
||||||
**kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
def _make_authorization_headers(client_id, client_secret):
|
def _make_authorization_headers(client_id, client_secret):
|
||||||
auth_header = base64.b64encode(
|
auth_header = base64.b64encode(
|
||||||
str(client_id + ":" + client_secret).encode("ascii")
|
str(client_id + ":" + client_secret).encode("ascii")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user