File tree Expand file tree Collapse file tree 4 files changed +36
-0
lines changed
Expand file tree Collapse file tree 4 files changed +36
-0
lines changed Original file line number Diff line number Diff line change 44 SpotifyAuthenticationFailedError ,
55 SpotifyConnectionError ,
66 SpotifyError ,
7+ SpotifyForbiddenError ,
78 SpotifyNotFoundError ,
89 SpotifyRateLimitError ,
910)
6667 "SpotifyClient" ,
6768 "SpotifyConnectionError" ,
6869 "SpotifyError" ,
70+ "SpotifyForbiddenError" ,
6971 "SpotifyNotFoundError" ,
7072 "SpotifyRateLimitError" ,
7173 "Track" ,
Original file line number Diff line number Diff line change @@ -19,3 +19,7 @@ class SpotifyNotFoundError(SpotifyError):
1919
2020class SpotifyRateLimitError (SpotifyError ):
2121 """Spotify rate limit exception."""
22+
23+
24+ class SpotifyForbiddenError (SpotifyError ):
25+ """Spotify forbidden (403) exception."""
Original file line number Diff line number Diff line change 1616from spotifyaio .exceptions import (
1717 SpotifyConnectionError ,
1818 SpotifyError ,
19+ SpotifyForbiddenError ,
1920 SpotifyNotFoundError ,
2021)
2122from spotifyaio .models import (
@@ -153,6 +154,10 @@ async def _request(
153154
154155 text = await response .text ()
155156
157+ if response .status == 403 :
158+ # 403 Forbidden
159+ raise SpotifyForbiddenError (text )
160+
156161 if '"status": 404' in text :
157162 msg = f"Resource not found: { uri } "
158163 raise SpotifyNotFoundError (msg )
Original file line number Diff line number Diff line change 1616 SpotifyClient ,
1717 SpotifyConnectionError ,
1818 SpotifyError ,
19+ SpotifyForbiddenError ,
1920 SpotifyNotFoundError ,
2021)
2122from spotifyaio .models import SearchType
@@ -191,6 +192,30 @@ async def test_get_no_playback_state(
191192 )
192193
193194
195+ async def test_user_has_no_access_to_webapi (
196+ authenticated_client : SpotifyClient ,
197+ responses : aioresponses ,
198+ ) -> None :
199+ """Test that SpotifyForbiddenError is raised if user has no access to WebAPI."""
200+ text = (
201+ "Check settings on developer.spotify.com/dashboard, "
202+ "the user may not be registered."
203+ )
204+ responses .get (f"{ SPOTIFY_URL } /v1/me" , status = 403 , body = text )
205+ with pytest .raises (
206+ SpotifyForbiddenError ,
207+ match = text ,
208+ ):
209+ await authenticated_client .get_current_user ()
210+ responses .assert_called_once_with (
211+ f"{ SPOTIFY_URL } /v1/me" ,
212+ METH_GET ,
213+ headers = HEADERS ,
214+ params = None ,
215+ json = None ,
216+ )
217+
218+
194219async def test_transfer_playback (
195220 authenticated_client : SpotifyClient ,
196221 responses : aioresponses ,
You can’t perform that action at this time.
0 commit comments