diff options
author | Adrian Sampson <adrian@radbox.org> | 2022-07-15 10:58:10 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-15 10:58:10 -0400 |
commit | 50825dbfc8443869ff2f1cad406e310a597c1aad (patch) | |
tree | d28107267cbd76255840a1ca3e912d81d6982452 | |
parent | 7209c5f922ad7bcc9ae88991e1c5cf5494a02577 (diff) | |
parent | 06825e0729abf1897db62f122b31e843e0b8074f (diff) |
Merge pull request #4413 from arsaboo/spotify_debug
Fix: Crash when search encounters a 404 error
-rw-r--r-- | beetsplug/spotify.py | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/beetsplug/spotify.py b/beetsplug/spotify.py index ef7407b36..30fbabc06 100644 --- a/beetsplug/spotify.py +++ b/beetsplug/spotify.py @@ -194,8 +194,9 @@ class SpotifyPlugin(MetadataSourcePlugin, BeetsPlugin): 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( @@ -395,15 +396,17 @@ class SpotifyPlugin(MetadataSourcePlugin, BeetsPlugin): 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), |