From 893b51c75607472af2655c8280143e327ec24c86 Mon Sep 17 00:00:00 2001 From: Philipp Wolfer Date: Tue, 25 Jun 2024 07:40:52 +0200 Subject: [PATCH] deezerart: improve error handling Do not crash if the response does not include a "data" object or is an error --- plugins/deezerart/deezer/client.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/plugins/deezerart/deezer/client.py b/plugins/deezerart/deezer/client.py index b761ef99..947608fd 100644 --- a/plugins/deezerart/deezer/client.py +++ b/plugins/deezerart/deezer/client.py @@ -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)},