Skip to content

Commit

Permalink
Improve API request error logging
Browse files Browse the repository at this point in the history
  • Loading branch information
MoojMidge committed Oct 8, 2024
1 parent efb1997 commit 818b4a1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions resources/lib/youtube_plugin/kodion/network/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def request(self, url, method='GET',
error_details.update(_detail)
if _response is not None:
response = _response
response_text = str(_response)
response_text = repr(_response)
if _trace is not None:
stack_trace = _trace
if _exc is not None:
Expand All @@ -168,7 +168,7 @@ def request(self, url, method='GET',
error_info = str(exc)

if response_text:
response_text = 'Request response:\n{0}'.format(response_text)
response_text = 'Response:\n\t|{0}|'.format(response_text)

if stack_trace:
stack_trace = (
Expand Down
8 changes: 5 additions & 3 deletions resources/lib/youtube_plugin/youtube/client/youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -1968,14 +1968,16 @@ def _error_hook(self, **kwargs):
if getattr(exc, 'pass_data', False):
data = json_data
else:
data = None
data = kwargs['response']
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
info = 'Exception:\n\t|{exc!r}|'
details = kwargs
return None, info, details, data, None, exception

details = json_data['error']
reason = details.get('errors', [{}])[0].get('reason', 'Unknown')
Expand Down Expand Up @@ -2005,7 +2007,7 @@ def _error_hook(self, **kwargs):
time_ms=timeout)

info = ('API error: {reason}\n'
'exc: |{exc}|\n'
'exc: |{exc!r}|\n'
'message: |{message}|')
details = {'reason': reason, 'message': message}
return '', info, details, data, False, exception
Expand Down

0 comments on commit 818b4a1

Please sign in to comment.