From 23d61fa2c9af4e9e2f6471f1d33af1a9054983a2 Mon Sep 17 00:00:00 2001 From: Dag Wieers Date: Tue, 1 Sep 2020 01:39:35 +0200 Subject: [PATCH 1/3] Improve error messages on failures I started injecting failures to Kodi and this makes it handle them better. --- .../resource.language.en_gb/strings.po | 2 +- .../resource.language.nl_nl/strings.po | 4 ++-- resources/lib/apihelper.py | 4 ++++ resources/lib/kodiutils.py | 18 ++++++++++-------- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/resources/language/resource.language.en_gb/strings.po b/resources/language/resource.language.en_gb/strings.po index 77860d4a..148cda3c 100644 --- a/resources/language/resource.language.en_gb/strings.po +++ b/resources/language/resource.language.en_gb/strings.po @@ -967,7 +967,7 @@ msgid "No connection" msgstr "" msgctxt "#30969" -msgid "There is a problem connecting to the Internet. This could be related to Kodi, your network, your ISP or VRT NU. Check out the Kodi log for more details." +msgid "There is a problem connecting to the Internet. This could be related to Kodi, your network, your ISP or VRT NU. Check out the Kodi log for more details.\n[COLOR=yellow]{reason}[/COLOR]" msgstr "" msgctxt "#30970" diff --git a/resources/language/resource.language.nl_nl/strings.po b/resources/language/resource.language.nl_nl/strings.po index 6fd9a9fb..b8bf529f 100644 --- a/resources/language/resource.language.nl_nl/strings.po +++ b/resources/language/resource.language.nl_nl/strings.po @@ -967,8 +967,8 @@ msgid "No connection" msgstr "Geen verbinding" msgctxt "#30969" -msgid "There is a problem connecting to the Internet. This could be related to Kodi, your network, your ISP or VRT NU. Check out the Kodi log for more details." -msgstr "Er is een probleem met het verbinden met internet. Dit kan liggen aan Kodi, aan jouw netwerk, aan jouw ISP of aan VRT NU. Bekijk de Kodi-log voor meer details." +msgid "There is a problem connecting to the Internet. This could be related to Kodi, your network, your ISP or VRT NU. Check out the Kodi log for more details.\n[COLOR=yellow]{reason}[/COLOR]" +msgstr "Er is een probleem met het verbinden met internet. Dit kan liggen aan Kodi, aan jouw netwerk, aan jouw ISP of aan VRT NU. Bekijk de Kodi-log voor meer details.\n[COLOR=yellow]{reason}[/COLOR]" msgctxt "#30970" msgid "VRT NU authentication failed" diff --git a/resources/lib/apihelper.py b/resources/lib/apihelper.py index 01761131..2d0c9791 100644 --- a/resources/lib/apihelper.py +++ b/resources/lib/apihelper.py @@ -596,6 +596,10 @@ def get_episodes(self, program=None, season=None, episodes=None, category=None, else: search_json = get_url_json(url=search_url, fail={}) + # Fail more gracefully on network errors + if not search_json: + return [] + # Check for multiple seasons seasons = [] if 'facets[seasonTitle]' not in unquote(search_url): diff --git a/resources/lib/kodiutils.py b/resources/lib/kodiutils.py index ce8046e6..750119d4 100644 --- a/resources/lib/kodiutils.py +++ b/resources/lib/kodiutils.py @@ -1120,22 +1120,24 @@ def open_url(url, data=None, headers=None, method=None, cookiejar=None, follow_r log_error('HTTP Error {code}: {reason}', code=code, reason=reason) return None except URLError as exc: - ok_dialog(heading=localize(30968), message=localize(30969)) - log_error('URLError: {error}\nurl: {url}', error=exc.reason, url=url) + ok_dialog(heading=localize(30968), message=localize(30969, reason=exc.reason)) + log_error('URLError: {reason}\nurl: {url}', reason=exc.reason, url=url) return None except SSLError as exc: # TODO: Include the error message in the notification window - ok_dialog(heading=localize(30968), message=localize(30969)) if hasattr(exc, 'reason'): # Python 2.7.9+, but still failed on Python 2.7.16 - log_error('SSLError: {error} ({library})\nurl: {url}', error=exc.reason, library=exc.library, url=url) + ok_dialog(heading=localize(30968), message=localize(30969, reason=exc.reason)) + log_error('SSLError: {reason} ({library})\nurl: {url}', reason=exc.reason, library=exc.library, url=url) elif isinstance(exc, list): - log_error('SSLError: {error} ({errno})\nurl: {url}', errno=exc[0], error=exc[1], url=url) + ok_dialog(heading=localize(30968), message=localize(30969, reason='{e[1]} ({e[0]})'.format(e=exc))) + log_error('SSLError: {reason} ({errno})\nurl: {url}', errno=exc[0], reason=exc[1], url=url) else: - log_error('SSLError: {error}\nurl: {url}', error=str(exc), url=url) + ok_dialog(heading=localize(30968), message=localize(30969, reason=str(exc))) + log_error('SSLError: {reason}\nurl: {url}', reason=str(exc), url=url) return None except timeout as exc: - ok_dialog(heading=localize(30968), message=localize(30969)) - log_error('Timeout: {error}\nurl: {url}', error=exc.reason, url=url) + ok_dialog(heading=localize(30968), message=localize(30969, reason=exc.reason)) + log_error('Timeout: {reason}\nurl: {url}', reason=exc.reason, url=url) return None From f2424aec8dd41b980258f8fa543cabb8989d5ec9 Mon Sep 17 00:00:00 2001 From: Dag Wieers Date: Wed, 9 Sep 2020 02:19:02 +0200 Subject: [PATCH 2/3] Make dialog a bit more specific --- resources/lib/kodiutils.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/resources/lib/kodiutils.py b/resources/lib/kodiutils.py index 750119d4..b5e93c27 100644 --- a/resources/lib/kodiutils.py +++ b/resources/lib/kodiutils.py @@ -1094,30 +1094,28 @@ def open_url(url, data=None, headers=None, method=None, cookiejar=None, follow_r else: # Python 2.7 url_length = len(req.get_selector()) if exc.code == 400 and 7600 <= url_length <= 8192: - ok_dialog(heading='HTTP Error 400', message=localize(30967)) + ok_dialog(heading='HTTP Error 400: {reason}'.format(reason=exc.reason), message=localize(30967)) log_error('HTTP Error 400: Probably exceeded maximum url length: ' 'VRT Search API url has a length of {length} characters.', length=url_length) return None if exc.code == 413 and url_length > 8192: - ok_dialog(heading='HTTP Error 413', message=localize(30967)) + ok_dialog(heading='HTTP Error 413: {reason}'.format(reason=exc.reason), message=localize(30967)) log_error('HTTP Error 413: Exceeded maximum url length: ' 'VRT Search API url has a length of {length} characters.', length=url_length) return None if exc.code == 431: - ok_dialog(heading='HTTP Error 431', message=localize(30967)) + ok_dialog(heading='HTTP Error 431: {reason}'.format(reason=exc.reason), message=localize(30967)) log_error('HTTP Error 431: Request header fields too large: ' 'VRT Search API url has a length of {length} characters.', length=url_length) return None if exc.code == 401: - ok_dialog(heading='HTTP Error {code}'.format(code=exc.code), message='{}\n{}'.format(url, exc.reason)) + ok_dialog(heading='HTTP Error 401: {reason}'.format(reason=exc.reason), message='{}\n{}'.format(url, exc.reason)) log_error('HTTP Error {code}: {reason}', code=exc.code, reason=exc.reason) return None if exc.code in (400, 403) and exc.headers.get('Content-Type') and 'application/json' in exc.headers.get('Content-Type'): return exc - reason = exc.reason - code = exc.code - ok_dialog(heading='HTTP Error {code}'.format(code=code), message='{}\n{}'.format(url, reason)) - log_error('HTTP Error {code}: {reason}', code=code, reason=reason) + ok_dialog(heading='HTTP Error {code}: {reason}'.format(code=exc.code, reason=exc.reason), message='{}\n{}'.format(url, exc.reason)) + log_error('HTTP Error {code}: {reason}', code=exc.code, reason=exc.reason) return None except URLError as exc: ok_dialog(heading=localize(30968), message=localize(30969, reason=exc.reason)) From 905531c0004770427ed43ec59986fd5922933bc3 Mon Sep 17 00:00:00 2001 From: Dag Wieers Date: Wed, 9 Sep 2020 02:33:56 +0200 Subject: [PATCH 3/3] Exit add-on on fatal errors This prevents the add-on from entering an empty virtual directory when the request could not be handled. We may want to do this for other specific HTTP errors... --- resources/lib/kodiutils.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/resources/lib/kodiutils.py b/resources/lib/kodiutils.py index b5e93c27..63825e72 100644 --- a/resources/lib/kodiutils.py +++ b/resources/lib/kodiutils.py @@ -4,9 +4,9 @@ from __future__ import absolute_import, division, unicode_literals from contextlib import contextmanager -from sys import version_info from socket import timeout from ssl import SSLError +from sys import exit as sysexit, version_info import xbmc import xbmcaddon @@ -1097,17 +1097,17 @@ def open_url(url, data=None, headers=None, method=None, cookiejar=None, follow_r ok_dialog(heading='HTTP Error 400: {reason}'.format(reason=exc.reason), message=localize(30967)) log_error('HTTP Error 400: Probably exceeded maximum url length: ' 'VRT Search API url has a length of {length} characters.', length=url_length) - return None + sysexit('HTTP Error 400') if exc.code == 413 and url_length > 8192: ok_dialog(heading='HTTP Error 413: {reason}'.format(reason=exc.reason), message=localize(30967)) log_error('HTTP Error 413: Exceeded maximum url length: ' 'VRT Search API url has a length of {length} characters.', length=url_length) - return None + sysexit('HTTP Error 413') if exc.code == 431: ok_dialog(heading='HTTP Error 431: {reason}'.format(reason=exc.reason), message=localize(30967)) log_error('HTTP Error 431: Request header fields too large: ' 'VRT Search API url has a length of {length} characters.', length=url_length) - return None + sysexit('HTTP Error 431') if exc.code == 401: ok_dialog(heading='HTTP Error 401: {reason}'.format(reason=exc.reason), message='{}\n{}'.format(url, exc.reason)) log_error('HTTP Error {code}: {reason}', code=exc.code, reason=exc.reason)