mirror of
https://github.com/beetbox/beets.git
synced 2025-12-06 16:42:42 +01:00
Add 429 and 503 error handling
This commit is contained in:
parent
989ee5a69c
commit
b69de85d49
1 changed files with 12 additions and 2 deletions
|
|
@ -193,6 +193,16 @@ class SpotifyPlugin(MetadataSourcePlugin, BeetsPlugin):
|
||||||
elif e.response.status_code == 404:
|
elif e.response.status_code == 404:
|
||||||
raise SpotifyAPIError(f'API Error: {e.response.status_code}\n'
|
raise SpotifyAPIError(f'API Error: {e.response.status_code}\n'
|
||||||
f'URL: {url}\nparams: {params}')
|
f'URL: {url}\nparams: {params}')
|
||||||
|
elif e.response.status_code == 429:
|
||||||
|
seconds = response.headers.get('Retry-After',
|
||||||
|
DEFAULT_WAITING_TIME)
|
||||||
|
self._log.debug('Too many API requests. Retrying after {} \
|
||||||
|
seconds.', seconds)
|
||||||
|
time.sleep(int(seconds) + 1)
|
||||||
|
return self._handle_response(request_type, url, params=params)
|
||||||
|
elif e.response.status_code == 503:
|
||||||
|
self._log.error('Service Unavailable.')
|
||||||
|
raise SpotifyAPIError('Service Unavailable.')
|
||||||
elif e.response is not None:
|
elif e.response is not None:
|
||||||
raise SpotifyAPIError(
|
raise SpotifyAPIError(
|
||||||
f'{self.data_source} API error:\n{e.response.text}\n'
|
f'{self.data_source} API error:\n{e.response.text}\n'
|
||||||
|
|
@ -655,8 +665,8 @@ class SpotifyPlugin(MetadataSourcePlugin, BeetsPlugin):
|
||||||
track_data = self._handle_response(
|
track_data = self._handle_response(
|
||||||
requests.get, self.track_url + track_id
|
requests.get, self.track_url + track_id
|
||||||
)
|
)
|
||||||
self._log.debug('track_data: {}', track_data['popularity'])
|
self._log.debug('track_data: {}', track_data.get('popularity'))
|
||||||
return track_data['popularity']
|
return track_data.get('popularity')
|
||||||
|
|
||||||
def track_audio_features(self, track_id=None):
|
def track_audio_features(self, track_id=None):
|
||||||
"""Fetch track audio features by its Spotify ID."""
|
"""Fetch track audio features by its Spotify ID."""
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue