From 0333df5f87f9f863067ccfbc24c443dd4e66362d Mon Sep 17 00:00:00 2001 From: Berehum Date: Tue, 4 Feb 2025 10:05:17 +0100 Subject: [PATCH 1/3] Remove extensive error logging for spotify connection issues. --- amelie/narrowcasting/views.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/amelie/narrowcasting/views.py b/amelie/narrowcasting/views.py index f10d3e0..9be4d57 100644 --- a/amelie/narrowcasting/views.py +++ b/amelie/narrowcasting/views.py @@ -124,9 +124,9 @@ def room_spotify_now_playing(request): params={"market": "from_token"}, headers={"Authorization": "Bearer {}".format(assoc.access_token)} ) - except ConnectionError as e: + except ConnectionError: log = logging.getLogger("amelie.narrowcasting.views.room_spotify_now_playing") - log.warning(f"ConnectionError while retrieving player info: {e}") + log.warning(f"ConnectionError while retrieving player info") # Return empty response return JsonResponse({}) @@ -169,9 +169,9 @@ def room_spotify_pause(request): res = requests.put("https://api.spotify.com/v1/me/player/pause", headers={"Authorization": "Bearer {}".format(assoc.access_token)} ) - except ConnectionError as e: + except ConnectionError: log = logging.getLogger("amelie.narrowcasting.views.room_spotify_now_playing") - log.warning(f"ConnectionError while pausing Spotify player: {e}") + log.warning(f"ConnectionError while pausing Spotify player") # Return empty response return JsonResponse({}) @@ -214,9 +214,9 @@ def room_spotify_play(request): res = requests.put("https://api.spotify.com/v1/me/player/play", headers={"Authorization": "Bearer {}".format(assoc.access_token)} ) - except ConnectionError as e: + except ConnectionError: log = logging.getLogger("amelie.narrowcasting.views.room_spotify_now_playing") - log.warning(f"ConnectionError while unpausing Spotify player: {e}") + log.warning(f"ConnectionError while unpausing Spotify player") # Return empty response return JsonResponse({}) From 8b1d1548e121f0a26024a6e794394036839c4f14 Mon Sep 17 00:00:00 2001 From: supertom01 Date: Mon, 3 Mar 2025 21:45:20 +0100 Subject: [PATCH 2/3] Catch correct ConnectionError exception --- amelie/narrowcasting/views.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/amelie/narrowcasting/views.py b/amelie/narrowcasting/views.py index 9be4d57..af7f1c0 100644 --- a/amelie/narrowcasting/views.py +++ b/amelie/narrowcasting/views.py @@ -1,4 +1,5 @@ import logging +from typing import Union import requests from django.conf import settings @@ -124,9 +125,9 @@ def room_spotify_now_playing(request): params={"market": "from_token"}, headers={"Authorization": "Bearer {}".format(assoc.access_token)} ) - except ConnectionError: + except Union[requests.ConnectionError, ConnectionError] as e: log = logging.getLogger("amelie.narrowcasting.views.room_spotify_now_playing") - log.warning(f"ConnectionError while retrieving player info") + log.warning(f"ConnectionError while retrieving player info: {e}") # Return empty response return JsonResponse({}) From 00b6399a54305171c530bef640f8ae4baea3663f Mon Sep 17 00:00:00 2001 From: supertom01 Date: Mon, 3 Mar 2025 21:46:55 +0100 Subject: [PATCH 3/3] Catch correct ConnectionError exception --- amelie/narrowcasting/views.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/amelie/narrowcasting/views.py b/amelie/narrowcasting/views.py index af7f1c0..5055080 100644 --- a/amelie/narrowcasting/views.py +++ b/amelie/narrowcasting/views.py @@ -170,9 +170,9 @@ def room_spotify_pause(request): res = requests.put("https://api.spotify.com/v1/me/player/pause", headers={"Authorization": "Bearer {}".format(assoc.access_token)} ) - except ConnectionError: + except Union[requests.ConnectionError, ConnectionError] as e: log = logging.getLogger("amelie.narrowcasting.views.room_spotify_now_playing") - log.warning(f"ConnectionError while pausing Spotify player") + log.warning(f"ConnectionError while pausing Spotify player: {e}") # Return empty response return JsonResponse({}) @@ -215,9 +215,9 @@ def room_spotify_play(request): res = requests.put("https://api.spotify.com/v1/me/player/play", headers={"Authorization": "Bearer {}".format(assoc.access_token)} ) - except ConnectionError: + except Union[requests.ConnectionError, ConnectionError] as e: log = logging.getLogger("amelie.narrowcasting.views.room_spotify_now_playing") - log.warning(f"ConnectionError while unpausing Spotify player") + log.warning(f"ConnectionError while unpausing Spotify player: {e}") # Return empty response return JsonResponse({})