replace exception logging with exception level method

This commit is contained in:
aj 2020-07-01 11:03:43 +01:00
parent 2f3f22de0d
commit b6a7d3afe3
8 changed files with 41 additions and 38 deletions

View File

@ -371,4 +371,5 @@ def image(user=None):
try:
return jsonify({'images': net.get_playlist(uri_string=_playlist.uri).images, 'status': 'success'}), 200
except SpotifyNetworkException as e:
logger.exception(f'error occured during {_playlist.name} / {user.username} playlist retrieval')
return jsonify({'error': f"spotify error occured: {e.http_code}"}), 404

View File

@ -53,6 +53,7 @@ def play(user=None):
else:
return jsonify({'error': f"playlist {request_json['playlist_name']} not found"}), 404
except SpotifyNetworkException:
logger.exception(f'error occured during {user.username} playlists retrieval')
return jsonify({'error': "playlists not returned"}), 400
elif 'tracks' in request_json:

View File

@ -63,6 +63,7 @@ def count(user=None):
else:
return jsonify({'error': f'playlist {playlist_name} not found'}), 404
except SpotifyNetworkException:
logger.exception(f'error occured during {user.username} playlists retrieval')
return jsonify({'error': f'playlist {playlist_name} not found'}), 404

View File

@ -52,8 +52,8 @@ def get_authed_spotify_network(user):
try:
net.refresh_user_info()
except SpotifyNetworkException as e:
logger.error(f'error refreshing user info for {user.username} = {e}')
except SpotifyNetworkException:
logger.exception(f'error refreshing user info for {user.username}')
return net
else:

View File

@ -17,6 +17,6 @@ def create_playlist(user, name):
try:
return net.create_playlist(net.user.user.display_name, name)
except SpotifyNetworkException as e:
logger.error(f'error ocurred {user.username} / {name} - {e}')
except SpotifyNetworkException:
logger.exception(f'error ocurred {user.username} / {name}')
return

View File

@ -38,8 +38,8 @@ def refresh_lastfm_track_stats(username, playlist_name):
try:
spotify_playlist = spotnet.get_playlist(uri=Uri(playlist.uri))
except SpotifyNetworkException as e:
logger.error(f'error retrieving spotify playlist {username} / {playlist_name} - {e}')
except SpotifyNetworkException:
logger.exception(f'error retrieving spotify playlist {username} / {playlist_name}')
return
track_count = counter.count_playlist(playlist=spotify_playlist)
@ -49,8 +49,8 @@ def refresh_lastfm_track_stats(username, playlist_name):
percent = round((track_count * 100) / user_count, 2)
else:
percent = 0
except LastFMNetworkException as e:
logger.error(f'error while retrieving user scrobble count - {e}')
except LastFMNetworkException:
logger.exception(f'error while retrieving user scrobble count {username} / {playlist_name}')
percent = 0
playlist.lastfm_stat_count = track_count
@ -84,8 +84,8 @@ def refresh_lastfm_album_stats(username, playlist_name):
try:
spotify_playlist = spotnet.get_playlist(uri=Uri(playlist.uri))
except SpotifyNetworkException as e:
logger.error(f'error retrieving spotify playlist {username} / {playlist_name} - {e}')
except SpotifyNetworkException:
logger.exception(f'error retrieving spotify playlist {username} / {playlist_name}')
return
album_count = counter.count_playlist(playlist=spotify_playlist, query_album=True)
@ -95,8 +95,8 @@ def refresh_lastfm_album_stats(username, playlist_name):
album_percent = round((album_count * 100) / user_count, 2)
else:
album_percent = 0
except LastFMNetworkException as e:
logger.error(f'error while retrieving user scrobble count - {e}')
except LastFMNetworkException:
logger.exception(f'error while retrieving user scrobble count {username} / {playlist_name}')
album_percent = 0
playlist.lastfm_stat_album_count = album_count
@ -130,8 +130,8 @@ def refresh_lastfm_artist_stats(username, playlist_name):
try:
spotify_playlist = spotnet.get_playlist(uri=Uri(playlist.uri))
except SpotifyNetworkException as e:
logger.error(f'error retrieving spotify playlist {username} / {playlist_name} - {e}')
except SpotifyNetworkException:
logger.exception(f'error retrieving spotify playlist {username} / {playlist_name}')
return
artist_count = counter.count_playlist(playlist=spotify_playlist, query_artist=True)
@ -141,8 +141,8 @@ def refresh_lastfm_artist_stats(username, playlist_name):
artist_percent = round((artist_count * 100) / user_count, 2)
else:
artist_percent = 0
except LastFMNetworkException as e:
logger.error(f'error while retrieving user scrobble count - {e}')
except LastFMNetworkException:
logger.exception(f'error while retrieving user scrobble count {username} / {playlist_name}')
artist_percent = 0
playlist.lastfm_stat_artist_count = artist_count

View File

@ -52,8 +52,8 @@ def run_user_playlist(username, playlist_name):
try:
user_playlists = net.get_user_playlists()
except SpotifyNetworkException as e:
logger.error(f'error occured while retrieving playlists {username} / {playlist_name} - {e}')
except SpotifyNetworkException:
logger.exception(f'error occured while retrieving playlists {username} / {playlist_name}')
return
part_generator = PartGenerator(user=user)
@ -77,8 +77,8 @@ def run_user_playlist(username, playlist_name):
playlist_tracks += _tracks
else:
logger.warning(f'no tracks returned for {uri} {username} / {playlist_name}')
except SpotifyNetworkException as e:
logger.error(f'error occured while retrieving {uri} {username} / {playlist_name} - {e}')
except SpotifyNetworkException:
logger.exception(f'error occured while retrieving {uri} {username} / {playlist_name}')
except ValueError: # is a playlist name
part_playlist = next((i for i in user_playlists if i.name == part_name), None)
@ -92,8 +92,8 @@ def run_user_playlist(username, playlist_name):
playlist_tracks += part_playlist_tracks
else:
logger.warning(f'no tracks returned for {part_playlist.name} {username} / {playlist_name}')
except SpotifyNetworkException as e:
logger.error(f'error occured while retrieving {part_name} {username} / {playlist_name} - {e}')
except SpotifyNetworkException:
logger.exception(f'error occured while retrieving {part_name} {username} / {playlist_name}')
playlist_tracks = remove_local(playlist_tracks)
@ -105,8 +105,8 @@ def run_user_playlist(username, playlist_name):
playlist_tracks += library_tracks
else:
logger.error(f'error getting library tracks {username} / {playlist_name}')
except SpotifyNetworkException as e:
logger.error(f'error occured while retrieving library tracks {username} / {playlist_name} - {e}')
except SpotifyNetworkException:
logger.exception(f'error occured while retrieving library tracks {username} / {playlist_name}')
# PLAYLIST TYPE SPECIFIC
if playlist.type == 'recents':
@ -159,8 +159,8 @@ def run_user_playlist(username, playlist_name):
playlist_tracks += recommendations.tracks
else:
logger.error(f'error getting recommendations {username} / {playlist_name}')
except SpotifyNetworkException as e:
logger.error(f'error occured while generating recommendations {username} / {playlist_name} - {e}')
except SpotifyNetworkException:
logger.exception(f'error occured while generating recommendations {username} / {playlist_name}')
# DEDUPLICATE
playlist_tracks = deduplicate_by_name(playlist_tracks)
@ -184,11 +184,11 @@ def run_user_playlist(username, playlist_name):
try:
net.change_playlist_details(Uri(playlist.uri), description=string)
except SpotifyNetworkException as e:
logger.error(f'error changing description for {username} / {playlist_name} - {e}')
except SpotifyNetworkException:
logger.exception(f'error changing description for {username} / {playlist_name}')
except SpotifyNetworkException as e:
logger.error(f'error executing {username} / {playlist_name} - {e}')
except SpotifyNetworkException:
logger.exception(f'error executing {username} / {playlist_name}')
playlist.last_updated = datetime.datetime.utcnow()
playlist.update()

View File

@ -37,8 +37,8 @@ def update_tag(username, tag_id):
tag_count = 0
try:
user_scrobbles = net.get_user_scrobble_count()
except LastFMNetworkException as e:
logger.error(f'error retrieving scrobble count - {e}')
except LastFMNetworkException:
logger.exception(f'error retrieving scrobble count {username} / {tag_id}')
user_scrobbles = 0
artists = []
@ -49,8 +49,8 @@ def update_tag(username, tag_id):
if net_artist is not None:
artist['count'] = net_artist.user_scrobbles
tag_count += net_artist.user_scrobbles
except LastFMNetworkException as e:
logger.error(f'error during artist retrieval - {e}')
except LastFMNetworkException:
logger.exception(f'error during artist retrieval {username} / {tag_id}')
artists.append(artist)
@ -64,8 +64,8 @@ def update_tag(username, tag_id):
if album['artist'].lower() not in [i.lower() for i in [j['name'] for j in artists]]:
tag_count += net_album.user_scrobbles
except LastFMNetworkException as e:
logger.error(f'error during album retrieval - {e}')
except LastFMNetworkException:
logger.exception(f'error during album retrieval {username} / {tag_id}')
albums.append(album)
@ -79,8 +79,8 @@ def update_tag(username, tag_id):
if track['artist'].lower() not in [i.lower() for i in [j['name'] for j in artists]]:
tag_count += net_track.user_scrobbles
except LastFMNetworkException as e:
logger.error(f'error during track retrieval - {e}')
except LastFMNetworkException:
logger.exception(f'error during track retrieval {username} / {tag_id}')
tracks.append(track)