Skip to content

Commit

Permalink
deezerart: improve error handling
Browse files Browse the repository at this point in the history
Do not crash if the response does not include a "data" object or is an error
  • Loading branch information
phw committed Jun 25, 2024
1 parent fa64e85 commit 1577261
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion plugins/deezerart/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PLUGIN_NAME = "Deezer cover art"
PLUGIN_AUTHOR = "Fabio Forni <livingsilver94>"
PLUGIN_DESCRIPTION = "Fetch cover arts from Deezer"
PLUGIN_VERSION = '1.2'
PLUGIN_VERSION = '1.2.1'
PLUGIN_API_VERSIONS = ['2.5']
PLUGIN_LICENSE = "GPL-3.0-or-later"
PLUGIN_LICENSE_URL = "https://www.gnu.org/licenses/gpl-3.0.html"
Expand Down
10 changes: 9 additions & 1 deletion plugins/deezerart/deezer/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,15 @@ def handler(document: QByteArray, _: QNetworkReply, error: Optional[QNetworkRepl
except json.JSONDecodeError:
callback([], error)
else:
callback([obj.parse_json(dct) for dct in parsed_doc['data']], error)
result = []
error = None
if 'data' in parsed_doc:
result = [obj.parse_json(dct) for dct in parsed_doc['data']]
elif 'error' in parsed_doc:
error = parsed_doc['error'].get('message', 'Deezer responded with an unknown error')
else:
error = 'Deezer returned an unexpected response'
callback(result, error)

self._get(path,
queryargs={'q': str(options)},
Expand Down

0 comments on commit 1577261

Please sign in to comment.