From a82eaa37c03f19f5236a38c07b73de803366c650 Mon Sep 17 00:00:00 2001 From: Monkey Do Date: Tue, 10 Dec 2024 11:49:37 +0100 Subject: [PATCH] Catch error code+message from AppleMusic API Parse the response body for errors, log any error found --- troi/tools/utils.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/troi/tools/utils.py b/troi/tools/utils.py index 42f4486..1e17a46 100644 --- a/troi/tools/utils.py +++ b/troi/tools/utils.py @@ -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