Skip to content

Commit

Permalink
Merge pull request #4413 from arsaboo/spotify_debug
Browse files Browse the repository at this point in the history
Fix: Crash when search encounters a 404 error
  • Loading branch information
sampsyo authored Jul 15, 2022
2 parents 7209c5f + 06825e0 commit 50825db
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions beetsplug/spotify.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,9 @@ def _handle_response(self, request_type, url, params=None):
time.sleep(int(seconds) + 1)
return self._handle_response(request_type, url, params=params)
elif response.status_code == 404:
raise SpotifyAPIError("API Error {0.status_code} for {1}"
.format(response, url))
raise SpotifyAPIError("API Error: {}\nURL: {}\nparams: {}".
format(response.status_code, url,
params))
else:
raise ui.UserError(
'{} API error:\n{}\nURL:\n{}\nparams:\n{}'.format(
Expand Down Expand Up @@ -395,15 +396,17 @@ def _search_api(self, query_type, filters=None, keywords=''):
self._log.debug(
f"Searching {self.data_source} for '{query}'"
)
response_data = (
self._handle_response(
try:
response = self._handle_response(
requests.get,
self.search_url,
params={'q': query, 'type': query_type},
)
.get(query_type + 's', {})
.get('items', [])
)
except SpotifyAPIError as e:
self._log.debug('Spotify API error: {}', e)
return []
response_data = (response.get(query_type + 's', {})
.get('items', []))
self._log.debug(
"Found {} result(s) from {} for '{}'",
len(response_data),
Expand Down

0 comments on commit 50825db

Please sign in to comment.