Give a reason for player errors in SpotifyException (#543)

* Added reason to SpotifyException

* Updated the changelog

* Fixing code style

Co-authored-by: Stéphane Bruckert <stephane.bruckert@gmail.com>
This commit is contained in:
Esamanoaz 2020-07-23 09:08:47 -07:00 committed by GitHub
parent bb4c98033f
commit 36bbf7d15e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 3 deletions

View File

@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Proper replacements for all deprecated playlist endpoints - Proper replacements for all deprecated playlist endpoints
(See https://developer.spotify.com/community/news/2018/06/12/changes-to-playlist-uris/ and below) (See https://developer.spotify.com/community/news/2018/06/12/changes-to-playlist-uris/ and below)
- Allow for OAuth 2.0 authorization by instructing the user to open the URL in a browser instead of opening the browser. - Allow for OAuth 2.0 authorization by instructing the user to open the URL in a browser instead of opening the browser.
- Reason for 403 error in SpotifyException
- Support for the PKCE Auth Flow - Support for the PKCE Auth Flow
- Support to advertise different language to Spotify - Support to advertise different language to Spotify

View File

@ -248,6 +248,10 @@ class Spotify(object):
msg = response.json()["error"]["message"] msg = response.json()["error"]["message"]
except (ValueError, KeyError): except (ValueError, KeyError):
msg = "error" msg = "error"
try:
reason = response.json()["error"]["reason"]
except (ValueError, KeyError):
reason = None
logger.error('HTTP Error for %s to %s returned %s due to %s', logger.error('HTTP Error for %s to %s returned %s due to %s',
method, url, response.status_code, msg) method, url, response.status_code, msg)
@ -256,6 +260,7 @@ class Spotify(object):
response.status_code, response.status_code,
-1, -1,
"%s:\n %s" % (response.url, msg), "%s:\n %s" % (response.url, msg),
reason=reason,
headers=response.headers, headers=response.headers,
) )
except requests.exceptions.RetryError: except requests.exceptions.RetryError:

View File

@ -1,9 +1,10 @@
class SpotifyException(Exception): class SpotifyException(Exception):
def __init__(self, http_status, code, msg, headers=None): def __init__(self, http_status, code, msg, reason=None, headers=None):
self.http_status = http_status self.http_status = http_status
self.code = code self.code = code
self.msg = msg self.msg = msg
self.reason = reason
# `headers` is used to support `Retry-After` in the event of a # `headers` is used to support `Retry-After` in the event of a
# 429 status code. # 429 status code.
if headers is None: if headers is None:
@ -11,5 +12,5 @@ class SpotifyException(Exception):
self.headers = headers self.headers = headers
def __str__(self): def __str__(self):
return 'http status: {0}, code:{1} - {2}'.format( return 'http status: {0}, code:{1} - {2}, reason: {3}'.format(
self.http_status, self.code, self.msg) self.http_status, self.code, self.msg, self.reason)