Skip to content

Commit

Permalink
Raise exception (ObjectNotFound) when no result or when invalid isrc/…
Browse files Browse the repository at this point in the history
…upc is used
  • Loading branch information
tehkillerbee committed Sep 5, 2024
1 parent ebe820a commit 3bfefb8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 8 additions & 0 deletions tidalapi/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,11 @@ class ManifestDecodeError(Exception):

class MPDNotAvailableError(Exception):
pass


class InvalidISRC(Exception):
pass


class InvalidUPC(Exception):
pass
6 changes: 4 additions & 2 deletions tidalapi/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -882,13 +882,14 @@ def get_tracks_by_isrc(self, isrc: str) -> list[media.Track]:
return [self.track(tr["id"]) for tr in res["data"]]
else:
log.warning("No matching tracks found for ISRC '%s'", isrc)
return []
raise ObjectNotFound
except HTTPError:
log.error("Invalid ISRC code '%s'", isrc)
# Get latest detailed error response and return the response given from the TIDAL api
resp_str = self.request.get_latest_err_response_str()
if resp_str:
log.error("API Response: '%s'", resp_str)
raise InvalidISRC

def get_albums_by_barcode(self, barcode: str) -> list[album.Album]:
"""Function to search all albums with a specific UPC code (eg. "196589525444")
Expand All @@ -913,13 +914,14 @@ def get_albums_by_barcode(self, barcode: str) -> list[album.Album]:
return [self.album(alb["id"]) for alb in res["data"]]
else:
log.warning("No matching albums found for UPC barcode '%s'", barcode)
return []
raise ObjectNotFound
except HTTPError:
log.error("Invalid UPC barcode '%s'.", barcode)
# Get latest detailed error response and return the response given from the TIDAL api
resp_str = self.request.get_latest_err_response_str()
if resp_str:
log.error("API Response: '%s'", resp_str)
raise InvalidUPC

def video(self, video_id: Optional[str] = None) -> media.Video:
"""Function to create a Video object with access to the session instance in a
Expand Down

0 comments on commit 3bfefb8

Please sign in to comment.