[GH-ISSUE #1160] All Spotipy exceptions should inherit from SpotifyException #684

Closed
opened 2026-02-28 00:00:49 +03:00 by kerem · 2 comments
Owner

Originally created by @vitorbaptista on GitHub (Oct 5, 2024).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/1160

Is your feature request related to a problem? Please describe.

I'd like to be able to catch any exceptions raised by Spotipy. I thought this was what spotipy.client.SpotifyException was for, but spotipy.oauth2.SpotifyOauthError inherits from Python's base Exception.

Describe the solution you'd like

If I catch spotipy.client.SpotifyException I should catch all exceptions raised by Spotipy.

Describe alternatives you've considered

Explicitly using except (spotipy.client.SpotifyException, spotipy.oauth2.SpotifyOauthError) as e. This works, but feels a bit too coupled.

Originally created by @vitorbaptista on GitHub (Oct 5, 2024). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/1160 **Is your feature request related to a problem? Please describe.** I'd like to be able to catch any exceptions raised by Spotipy. I thought this was what `spotipy.client.SpotifyException` was for, but `spotipy.oauth2.SpotifyOauthError` inherits from Python's base `Exception`. **Describe the solution you'd like** If I catch `spotipy.client.SpotifyException` I should catch all exceptions raised by Spotipy. **Describe alternatives you've considered** Explicitly using `except (spotipy.client.SpotifyException, spotipy.oauth2.SpotifyOauthError) as e`. This works, but feels a bit too coupled.
kerem 2026-02-28 00:00:49 +03:00
Author
Owner

@dieser-niko commented on GitHub (Oct 6, 2024):

@stephanebruckert any objections? Otherwise I would just start working on a PR.
I don't see any reason why it should stay this way.

Currently there are 3 exception classes:

  • exceptions.SpotifyException/client.SpotifyException
  • oauth2.SpotifyOauthError
  • oauth2.SpotifyStateError

As a change, I would suggest adding a new exception called SpotifyBaseException with no specific attributes, as the SpotifyOauthError doesn't share any attributes with SpotifyException.

Also while we're at it, I would move the errors from oauth2.py to the already existing exceptions.py file, because they don't need any imports.

<!-- gh-comment-id:2395511550 --> @dieser-niko commented on GitHub (Oct 6, 2024): @stephanebruckert any objections? Otherwise I would just start working on a PR. I don't see any reason why it should stay this way. Currently there are 3 exception classes: - `exceptions.SpotifyException`/`client.SpotifyException` - `oauth2.SpotifyOauthError` - `oauth2.SpotifyStateError` As a change, I would suggest adding a new exception called `SpotifyBaseException` with no specific attributes, as the `SpotifyOauthError` doesn't share any attributes with `SpotifyException`. Also while we're at it, I would move the errors from `oauth2.py` to the already existing `exceptions.py` file, because they don't need any imports.
Author
Owner

@dieser-niko commented on GitHub (Oct 6, 2024):

I've created a PR, you can try it out by adding this to your requirements.txt file:

git+https://github.com/spotipy-dev/spotipy@1160-move-exceptions

I've implemented it like I've described in my last comment.

<!-- gh-comment-id:2395539132 --> @dieser-niko commented on GitHub (Oct 6, 2024): I've created a PR, you can try it out by adding this to your `requirements.txt` file: ``` git+https://github.com/spotipy-dev/spotipy@1160-move-exceptions ``` I've implemented it like I've described in my last comment.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/spotipy#684
No description provided.