Skip to content

Commit

Permalink
Replace built-in ConnectionError by requests.exceptions.ConnectionError
Browse files Browse the repository at this point in the history
  • Loading branch information
supertom01 committed Mar 4, 2025
1 parent 00b6399 commit 9f99373
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions amelie/narrowcasting/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging
from typing import Union

import requests
from django.conf import settings
Expand Down Expand Up @@ -62,7 +61,7 @@ def room_spotify_callback(request):
"client_id": settings.SPOTIFY_CLIENT_ID,
"client_secret": settings.SPOTIFY_CLIENT_SECRET
})
except ConnectionError as e:
except requests.exceptions.ConnectionError as e:
raise ValueError(_("ConnectionError while refreshing access token:") + f" {e}")

data = res.json()
Expand All @@ -86,7 +85,7 @@ def _spotify_refresh_token(association):
"client_id": settings.SPOTIFY_CLIENT_ID,
"client_secret": settings.SPOTIFY_CLIENT_SECRET
})
except ConnectionError as e:
except requests.exceptions.ConnectionError as e:
raise ValueError(_("ConnectionError while refreshing access token:") + f" {e}")

data = res.json()
Expand Down Expand Up @@ -125,7 +124,7 @@ def room_spotify_now_playing(request):
params={"market": "from_token"},
headers={"Authorization": "Bearer {}".format(assoc.access_token)}
)
except Union[requests.ConnectionError, ConnectionError] as e:
except requests.exceptions.ConnectionError as e:
log = logging.getLogger("amelie.narrowcasting.views.room_spotify_now_playing")
log.warning(f"ConnectionError while retrieving player info: {e}")
# Return empty response
Expand Down Expand Up @@ -170,7 +169,7 @@ def room_spotify_pause(request):
res = requests.put("https://api.spotify.com/v1/me/player/pause",
headers={"Authorization": "Bearer {}".format(assoc.access_token)}
)
except Union[requests.ConnectionError, ConnectionError] as e:
except requests.exceptions.ConnectionError as e:
log = logging.getLogger("amelie.narrowcasting.views.room_spotify_now_playing")
log.warning(f"ConnectionError while pausing Spotify player: {e}")
# Return empty response
Expand Down Expand Up @@ -215,7 +214,7 @@ def room_spotify_play(request):
res = requests.put("https://api.spotify.com/v1/me/player/play",
headers={"Authorization": "Bearer {}".format(assoc.access_token)}
)
except Union[requests.ConnectionError, ConnectionError] as e:
except requests.exceptions.ConnectionError as e:
log = logging.getLogger("amelie.narrowcasting.views.room_spotify_now_playing")
log.warning(f"ConnectionError while unpausing Spotify player: {e}")
# Return empty response
Expand Down

0 comments on commit 9f99373

Please sign in to comment.