Skip to content

Commit

Permalink
Catch error code+message from AppleMusic API
Browse files Browse the repository at this point in the history
Parse the response body for errors, log any error found
  • Loading branch information
MonkeyDo committed Dec 10, 2024
1 parent 3a09041 commit a82eaa3
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions troi/tools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ def get_playlist_tracks(self, playlist_id):
url = f"{APPLE_MUSIC_URL}/me/library/playlists/{playlist_id}/tracks?limit=100&offset={offset}"
response = self.session.get(url, headers=self.headers).json()
try:
if "errors" in response:
# https: // developer.apple.com/documentation/applemusicapi/errorsresponse
error_objects = response["errors"]
for error_object in error_objects:
error_message = error_object["detail"] if "detail" in error_object else error_object["title"]
logger.error(
f"Error code {error_object['status']}: {error_message}")
break

tracks_data = response["data"]
tracks.extend(tracks_data) if tracks_data else None

Expand Down

0 comments on commit a82eaa3

Please sign in to comment.