From ea3676eec0b3fba0dd08e768ec3416a730a9255c Mon Sep 17 00:00:00 2001 From: sfaulds Date: Mon, 14 Nov 2016 11:00:26 +1100 Subject: [PATCH] Surface download issue exceptions where appropriate instead of consuming them --- resources/lib/downloadutils.py | 7 ++++++- resources/lib/userclient.py | 8 ++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/resources/lib/downloadutils.py b/resources/lib/downloadutils.py index 790e8433..fdd000e2 100644 --- a/resources/lib/downloadutils.py +++ b/resources/lib/downloadutils.py @@ -249,6 +249,7 @@ class DownloadUtils(object): if action_type == "GET": raise Warning("Response Code 204: No Content for GET request") else: + # this is probably valid for DELETE and PUT return None elif response.status_code == requests.codes.ok: @@ -266,15 +267,18 @@ class DownloadUtils(object): except requests.exceptions.SSLError as error: log.error("invalid SSL certificate for: %s", url) + raise except requests.exceptions.ConnectTimeout as error: log.error("Server timeout at: %s", url) + raise except requests.exceptions.ConnectionError as error: # Make the addon aware of status if window('emby_online') != "false": log.error("Server unreachable at: %s", url) window('emby_online', value="false") + raise except requests.exceptions.HTTPError as error: @@ -301,7 +305,7 @@ class DownloadUtils(object): elif (response.headers['X-Application-Error-Code'] == "UnauthorizedAccessException"): # User tried to do something his emby account doesn't allow - pass + raise Warning('UnauthorizedAccessException') elif status not in ("401", "Auth"): # Tell userclient token has been revoked. @@ -314,6 +318,7 @@ class DownloadUtils(object): except requests.exceptions.RequestException as error: log.error("unknown error connecting to: %s", url) + raise # something went wrong so return a None as we have no valid data return None diff --git a/resources/lib/userclient.py b/resources/lib/userclient.py index 46f8b319..c108886f 100644 --- a/resources/lib/userclient.py +++ b/resources/lib/userclient.py @@ -77,11 +77,11 @@ class UserClient(threading.Thread): def verify_server(self): - url = "%s/emby/Users/Public?format=json" % self.get_server() - result = self.download(url, authenticate=False) - if result != "": # Specific verification, due to possibility of returning empty dict + try: + url = "%s/emby/Users/Public?format=json" % self.get_server() + self.download(url, authenticate=False) return True - else: + except: # Server connection failed return False