bots: Make wikipedia bot return an error message.
Previously the Wikipedia bot was replying with `null` in case of an error. A change has been made to return an error message if an error occurs.
This commit is contained in:
parent
e5e5868414
commit
d663dd2f49
|
@ -59,12 +59,13 @@ class TestWikipediaBot(StubBotTestCase):
|
||||||
|
|
||||||
# Incorrect status code
|
# Incorrect status code
|
||||||
bot_request = 'Zulip'
|
bot_request = 'Zulip'
|
||||||
bot_response = None
|
bot_response = 'Uh-Oh ! Sorry ,couldn\'t process the request right now.:slightly_frowning_face:\n' \
|
||||||
|
'Please try again later.'
|
||||||
|
|
||||||
with self.mock_http_conversation('test_status_code'):
|
with self.mock_http_conversation('test_status_code'):
|
||||||
self.verify_reply(bot_request, bot_response)
|
self.verify_reply(bot_request, bot_response)
|
||||||
|
|
||||||
# Request Exception
|
# Request Exception
|
||||||
bot_request = 'Z'
|
bot_request = 'Z'
|
||||||
bot_response = None
|
|
||||||
with mock_request_exception():
|
with mock_request_exception():
|
||||||
self.verify_reply(bot_request, bot_response)
|
self.verify_reply(bot_request, bot_response)
|
||||||
|
|
|
@ -56,12 +56,15 @@ class WikipediaHandler(object):
|
||||||
|
|
||||||
except requests.exceptions.RequestException:
|
except requests.exceptions.RequestException:
|
||||||
logging.error('broken link')
|
logging.error('broken link')
|
||||||
return None
|
return 'Uh-Oh ! Sorry ,couldn\'t process the request right now.:slightly_frowning_face:\n' \
|
||||||
|
'Please try again later.'
|
||||||
|
|
||||||
# Checking if the bot accessed the link.
|
# Checking if the bot accessed the link.
|
||||||
if data.status_code != 200:
|
if data.status_code != 200:
|
||||||
logging.error('Page not found.')
|
logging.error('Page not found.')
|
||||||
return None
|
return 'Uh-Oh ! Sorry ,couldn\'t process the request right now.:slightly_frowning_face:\n' \
|
||||||
|
'Please try again later.'
|
||||||
|
|
||||||
new_content = 'For search term:' + query + '\n'
|
new_content = 'For search term:' + query + '\n'
|
||||||
|
|
||||||
# Checking if there is content for the searched term
|
# Checking if there is content for the searched term
|
||||||
|
|
Loading…
Reference in a new issue