Skip to content

Commit

Permalink
Set default request exception hook parameters for Youtube API requests
Browse files Browse the repository at this point in the history
  • Loading branch information
MoojMidge committed Jan 17, 2024
1 parent a1e4879 commit 6c15a81
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions resources/lib/youtube_plugin/youtube/client/youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -1578,19 +1578,27 @@ 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

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
Expand All @@ -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':
Expand Down

0 comments on commit 6c15a81

Please sign in to comment.