From d663dd2f49d87f782a21e2743bcd569ce30bafb3 Mon Sep 17 00:00:00 2001 From: Sivagiri Visakan Date: Mon, 11 Dec 2017 22:51:09 +0530 Subject: [PATCH] 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. --- zulip_bots/zulip_bots/bots/wikipedia/test_wikipedia.py | 5 +++-- zulip_bots/zulip_bots/bots/wikipedia/wikipedia.py | 7 +++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/zulip_bots/zulip_bots/bots/wikipedia/test_wikipedia.py b/zulip_bots/zulip_bots/bots/wikipedia/test_wikipedia.py index bda2dd2..0824125 100755 --- a/zulip_bots/zulip_bots/bots/wikipedia/test_wikipedia.py +++ b/zulip_bots/zulip_bots/bots/wikipedia/test_wikipedia.py @@ -59,12 +59,13 @@ class TestWikipediaBot(StubBotTestCase): # Incorrect status code 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'): self.verify_reply(bot_request, bot_response) # Request Exception bot_request = 'Z' - bot_response = None with mock_request_exception(): self.verify_reply(bot_request, bot_response) diff --git a/zulip_bots/zulip_bots/bots/wikipedia/wikipedia.py b/zulip_bots/zulip_bots/bots/wikipedia/wikipedia.py index b74fb38..5373639 100644 --- a/zulip_bots/zulip_bots/bots/wikipedia/wikipedia.py +++ b/zulip_bots/zulip_bots/bots/wikipedia/wikipedia.py @@ -56,12 +56,15 @@ class WikipediaHandler(object): except requests.exceptions.RequestException: 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. if data.status_code != 200: 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' # Checking if there is content for the searched term