Skip to content

Commit 01abef8

Browse files
committed
fix: handle user not found
1 parent ea8ecc7 commit 01abef8

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

coderwall.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
from urllib.error import HTTPError
23
from urllib.request import urlopen
34

45
from errbot import BotPlugin, botcmd
@@ -14,17 +15,21 @@
1415

1516

1617
class Coderwall(BotPlugin):
17-
1818
@botcmd
1919
def coderwall(self, mess, args):
2020
"""Shows the badges of a coderwall user
2121
Example: !coderwall gbin
2222
"""
2323
if not args:
2424
return "Am I supposed to guess the username?..."
25-
args = args.strip()
26-
content = urlopen("http://coderwall.com/%s.json" % args)
27-
results = json.loads(content.read().decode())
28-
for badge in results["badges"]:
29-
self.send(mess.frm, BADGE % badge)
30-
return USER % results
25+
response = None
26+
username = args.strip()
27+
try:
28+
content = urlopen(f"http://coderwall.com/{username}.json")
29+
results = json.loads(content.read().decode())
30+
for badge in results["badges"]:
31+
self.send(mess.frm, BADGE % badge)
32+
response = USER % results
33+
except HTTPError:
34+
response = "User not found."
35+
return response

0 commit comments

Comments
 (0)