Skip to content

Commit

Permalink
Improve request error logging
Browse files Browse the repository at this point in the history
  • Loading branch information
MoojMidge committed Jan 10, 2024
1 parent d770077 commit 398fb6e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
14 changes: 10 additions & 4 deletions resources/lib/youtube_plugin/kodion/network/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def request(self, url, method='GET',
cert=cert,
json=json)
if not response:
raise self._default_exc[0]
raise self._default_exc[0](response=response)

if response_hook:
if response_hook_kwargs is None:
Expand All @@ -113,15 +113,16 @@ def request(self, url, method='GET',
response.raise_for_status()

except self._default_exc as exc:
response_text = exc.response and exc.response.text
exc_response = exc.response or response
response_text = exc_response and exc_response.text
stack_trace = format_stack()
error_details = {'exc': exc}

if error_hook:
if error_hook_kwargs is None:
error_hook_kwargs = {}
error_hook_kwargs['exc'] = exc
error_hook_kwargs['response'] = response or exc.response
error_hook_kwargs['response'] = exc_response
error_response = error_hook(**error_hook_kwargs)
_title, _info, _detail, _response, _trace, _exc = error_response
if _title is not None:
Expand All @@ -142,7 +143,12 @@ def request(self, url, method='GET',
error_title = 'Request failed'

if error_info is None:
error_info = str(exc)
try:
error_info = 'Status: {0.status_code} - {0.reason}'.format(
exc.response
)
except AttributeError:
error_info = str(exc)
elif '{' in error_info:
try:
error_info = error_info.format(**error_details)
Expand Down
4 changes: 2 additions & 2 deletions resources/lib/youtube_plugin/youtube/client/youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -1407,8 +1407,8 @@ 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', False) and json_data
exception = getattr(exc, 'raise_exc', False) and YouTubeException
data = getattr(exc, 'pass_data', None) and json_data
exception = getattr(exc, 'raise_exc', None) and YouTubeException

if not json_data or 'error' not in json_data:
return None, None, None, data, None, exception
Expand Down

0 comments on commit 398fb6e

Please sign in to comment.