From 6c15a81833685846ff7cdcc0825032cba51f9c7d Mon Sep 17 00:00:00 2001 From: MoojMidge <56883549+MoojMidge@users.noreply.github.com> Date: Thu, 18 Jan 2024 08:17:52 +1100 Subject: [PATCH] Set default request exception hook parameters for Youtube API requests --- .../lib/youtube_plugin/youtube/client/youtube.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/resources/lib/youtube_plugin/youtube/client/youtube.py b/resources/lib/youtube_plugin/youtube/client/youtube.py index ccb49226f..1c0dee48b 100644 --- a/resources/lib/youtube_plugin/youtube/client/youtube.py +++ b/resources/lib/youtube_plugin/youtube/client/youtube.py @@ -1578,10 +1578,12 @@ def _response_hook(self, **kwargs): try: json_data = response.json() if 'error' in json_data: + kwargs.setdefault('pass_data', True) raise YouTubeException('"error" in response JSON data', json_data=json_data, **kwargs) except ValueError as exc: + kwargs.setdefault('raise_exc', True) raise InvalidJSON(exc, **kwargs) response.raise_for_status() return json_data @@ -1589,8 +1591,14 @@ def _response_hook(self, **kwargs): def _error_hook(self, **kwargs): exc = kwargs['exc'] json_data = getattr(exc, 'json_data', None) - data = getattr(exc, 'pass_data', None) and json_data - exception = getattr(exc, 'raise_exc', None) and YouTubeException + if getattr(exc, 'pass_data', False): + data = json_data + else: + data = None + if getattr(exc, 'raise_exc', False): + exception = YouTubeException + else: + exception = None if not json_data or 'error' not in json_data: return None, None, None, data, None, exception @@ -1599,8 +1607,7 @@ def _error_hook(self, **kwargs): reason = details.get('errors', [{}])[0].get('reason', 'Unknown') message = strip_html_from_text(details.get('message', 'Unknown error')) - notify = getattr(exc, 'notify', True) - if notify: + if getattr(exc, 'notify', True): ok_dialog = False timeout = 5000 if reason == 'accessNotConfigured':