randomreddit: handle invalid json response

master
mutantmonkey 2012-06-23 21:56:16 -07:00
parent 6ecbe4ca18
commit 9f11190f0b
1 changed files with 5 additions and 2 deletions

View File

@ -35,8 +35,11 @@ def randomreddit(phenny, input):
except: except:
raise GrumbleError('Reddit or subreddit unreachable.') raise GrumbleError('Reddit or subreddit unreachable.')
reddit = json.loads(resp) try:
post = choice(reddit['data']['children']) reddit = json.loads(resp)
post = choice(reddit['data']['children'])
except:
raise GrumbleError('Error parsing response from Reddit.')
nsfw = False nsfw = False
if post['data']['over_18']: if post['data']['over_18']: