Networking module: display error message when API returns error

This commit is contained in:
nemunaire 2014-05-05 18:25:33 +02:00
parent 02d0d91df9
commit 0cceb8226d

View File

@ -120,7 +120,13 @@ def cmd_whois(msg):
except urllib.error.HTTPError as e: except urllib.error.HTTPError as e:
raise IRCException("HTTP error occurs: %s %s" % (e.code, e.reason)) raise IRCException("HTTP error occurs: %s %s" % (e.code, e.reason))
whois = json.loads(raw.read().decode())["WhoisRecord"] js = json.loads(raw.read().decode())
if "ErrorMessage" in js:
err = js["ErrorMessage"]
raise IRCException(js["ErrorMessage"]["msg"])
whois = js["WhoisRecord"]
res = Response(msg.sender, channel=msg.channel, nomore="No more whois information") res = Response(msg.sender, channel=msg.channel, nomore="No more whois information")