From cd677fb8ea63e05ca1463b4cb96393692aff9ed9 Mon Sep 17 00:00:00 2001 From: Robert Wilson Date: Thu, 17 Oct 2013 22:49:17 +0100 Subject: [PATCH 1/4] Add check for not accessing API --- plugin.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugin.py b/plugin.py index d7d0260..88e0d94 100644 --- a/plugin.py +++ b/plugin.py @@ -31,6 +31,10 @@ def userinfo(self, irc, msg, args, name): user = name day = int(epoch.time()/(60*60*24)) api_url = self.registryValue('protocol')+"://"+self.registryValue('user')+":"+self.registryValue('password')+"@"+self.registryValue('url') + try: + self.raise_for_status() + except RequestException as e: + irc.reply(e.str()) r=requests.get(api_url+"/users/"+user ) entry = r.json() if 'error' in entry: From 355915ad18d00287c952380145e059ef65e80588 Mon Sep 17 00:00:00 2001 From: Robert Wilson Date: Thu, 17 Oct 2013 22:52:51 +0100 Subject: [PATCH 2/4] Reposition error checking code --- plugin.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/plugin.py b/plugin.py index 88e0d94..9042b0d 100644 --- a/plugin.py +++ b/plugin.py @@ -31,11 +31,12 @@ def userinfo(self, irc, msg, args, name): user = name day = int(epoch.time()/(60*60*24)) api_url = self.registryValue('protocol')+"://"+self.registryValue('user')+":"+self.registryValue('password')+"@"+self.registryValue('url') + + r=requests.get(api_url+"/users/"+user ) try: - self.raise_for_status() + r.raise_for_status() except RequestException as e: - irc.reply(e.str()) - r=requests.get(api_url+"/users/"+user ) + irc.reply(e.str()) entry = r.json() if 'error' in entry: irc.reply(("Error: "+entry['error']).encode('utf-8')) From 42337eb07a64356971174cf73d5d6ed1247828ac Mon Sep 17 00:00:00 2001 From: Robert Wilson Date: Thu, 17 Oct 2013 22:52:51 +0100 Subject: [PATCH 3/4] Reposition error checking code --- plugin.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/plugin.py b/plugin.py index 88e0d94..9703303 100644 --- a/plugin.py +++ b/plugin.py @@ -31,11 +31,12 @@ def userinfo(self, irc, msg, args, name): user = name day = int(epoch.time()/(60*60*24)) api_url = self.registryValue('protocol')+"://"+self.registryValue('user')+":"+self.registryValue('password')+"@"+self.registryValue('url') - try: - self.raise_for_status() - except RequestException as e: - irc.reply(e.str()) + r=requests.get(api_url+"/users/"+user ) + try: + r.raise_for_status() + except RequestException as e: + irc.reply(e.str()) entry = r.json() if 'error' in entry: irc.reply(("Error: "+entry['error']).encode('utf-8')) From 5bbbf1ae58baa36e8786d7fb1718fa6cd9fa0502 Mon Sep 17 00:00:00 2001 From: Robert Wilson Date: Thu, 17 Oct 2013 23:16:27 +0100 Subject: [PATCH 4/4] Small Cleanup --- plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.py b/plugin.py index 686bd3f..e836b09 100644 --- a/plugin.py +++ b/plugin.py @@ -35,9 +35,9 @@ def userinfo(self, irc, msg, args, name): r=requests.get(api_url+"/users/"+user ) try: r.raise_for_status() - irc.reply(r.status_code) except requests.HTTPError as e: irc.reply(str(e)) + return entry = r.json() if 'error' in entry: irc.reply(("Error: "+entry['error']).encode('utf-8'))