22
33import requests
44from lxml import html
5+ from requests import HTTPError
56
67from cloudbot import hook
78from cloudbot .util import formatting , filesize , colors
@@ -30,7 +31,7 @@ def bingify(s):
3031
3132
3233@hook .command ("bing" , "b" )
33- def bing (text , bot ):
34+ def bing (text , bot , reply ):
3435 """<query> - returns the first bing search result for <query>"""
3536 api_key = bot .config .get ("api_keys" , {}).get ("bing_azure" )
3637
@@ -55,6 +56,12 @@ def bing(text, bot):
5556
5657 request = requests .get (API_URL , params = params , auth = (api_key , api_key ))
5758
59+ try :
60+ request .raise_for_status ()
61+ except HTTPError :
62+ reply ("Bing API error occurred." )
63+ raise
64+
5865 # I'm not even going to pretend to know why results are in ['d']['results'][0]
5966 j = request .json ()['d' ]['results' ][0 ]
6067
@@ -72,7 +79,7 @@ def bing(text, bot):
7279
7380
7481@hook .command ("bingimage" , "bis" )
75- def bingimage (text , bot ):
82+ def bingimage (text , bot , reply ):
7683 """<query> - returns the first bing image search result for <query>"""
7784 api_key = bot .config .get ("api_keys" , {}).get ("bing_azure" )
7885
@@ -98,6 +105,12 @@ def bingimage(text, bot):
98105
99106 request = requests .get (API_URL , params = params , auth = (api_key , api_key ))
100107
108+ try :
109+ request .raise_for_status ()
110+ except HTTPError :
111+ reply ("Bing API error occurred." )
112+ raise
113+
101114 # I'm not even going to pretend to know why results are in ['d']['results'][0]
102115 j = request .json ()['d' ]['results' ][0 ]
103116
0 commit comments