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 e859f90 commit 893b51c
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion plugins/deezerart/deezer/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,19 @@ def advanced_search(self, options: SearchOptions, callback: SearchCallback[obj.A
def handler(document: QByteArray, _: QNetworkReply, error: Optional[QNetworkReply.NetworkError]):
try:
parsed_doc = json.loads(str(document, 'utf-8'))
print(parsed_doc)
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 893b51c

Please sign in to comment.