Surface response when API login fails with 400
Closed this issue · 1 comments
enriquegh commented
Summary of issue
If you try to grab a token and your username/password are wrong, you get the error:
Traceback (most recent call last):
File "spotify_example.py", line 84, in <module>
data = st.start_session(args.user, args.password)
File "X/venv/lib/python3.7/site-packages/spotify_token.py", line 75, in start_session
_login(session, cookies, username, password, token)
File "X/venv/lib/python3.7/site-packages/spotify_token.py", line 33, in _login
response.raise_for_status()
File "X/venv/lib/python3.7/site-packages/requests/models.py", line 940, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://accounts.spotify.com/api/login
without knowing what caused this "Bad Request".
The 400 is returned by Spotify's API instead of a 401 or 403.
Actions to take
Catch the 400 error and surface the API response of:
{"error":"errorInvalidCredentials"}
to be more explicit of what happened.