Skip to content

Commit

Permalink
fix: catch SpotifyOauthError
Browse files Browse the repository at this point in the history
  • Loading branch information
billsioros committed Aug 9, 2021
1 parent bec1251 commit 72f8d42
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions dotify/_dotify.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from spotipy import Spotify as Client
from spotipy.client import logger
from spotipy.oauth2 import SpotifyClientCredentials
from spotipy.oauth2 import SpotifyClientCredentials, SpotifyOauthError

from dotify._decorators import classproperty

Expand Down Expand Up @@ -38,19 +38,25 @@ def __init__(
Args:
client_id (Optional[str]): your Spotify API client ID. Defaults to None
client_secret (Optional[str]): your Spotify API client secret. Defaults to None
Raises:
TypeError: In case the supplied credentials are invalid
"""
if client_id is None:
client_id = os.getenv("SPOTIFY_ID")

if client_secret is None:
client_secret = os.getenv("SPOTIFY_SECRET")

super().__init__(
client_credentials_manager=SpotifyClientCredentials(
client_id=client_id,
client_secret=client_secret,
),
)
try:
super().__init__(
client_credentials_manager=SpotifyClientCredentials(
client_id=client_id,
client_secret=client_secret,
),
)
except SpotifyOauthError as oauth_error:
raise TypeError("Invalid Credentials") from oauth_error

def __del__(self):
with contextlib.suppress(AttributeError):
Expand Down

0 comments on commit 72f8d42

Please sign in to comment.