From 1e84e2eb5e7e3ccf86689221ed9d04a859d66d9e Mon Sep 17 00:00:00 2001 From: Abhijeet Kaur Date: Tue, 1 Aug 2017 01:00:42 +0530 Subject: [PATCH] bots: Improve error handling of yoda bot when the service is unavailable. Frequent 503 errors throw index error exceptions which is misleading to debug. --- zulip_bots/zulip_bots/bots/yoda/yoda.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/zulip_bots/zulip_bots/bots/yoda/yoda.py b/zulip_bots/zulip_bots/bots/yoda/yoda.py index 2a7221b..5c11d5a 100644 --- a/zulip_bots/zulip_bots/bots/yoda/yoda.py +++ b/zulip_bots/zulip_bots/bots/yoda/yoda.py @@ -27,6 +27,9 @@ HELP_MESSAGE = ''' class ApiKeyError(Exception): '''raise this when there is an error with the Mashape Api Key''' +class ServiceUnavailableError(Exception): + '''raise this when the service is unavailable.''' + class YodaSpeakHandler(object): ''' @@ -67,6 +70,8 @@ class YodaSpeakHandler(object): return response.text if response.status_code == 403: raise ApiKeyError + if response.status_code == 503: + raise ServiceUnavailableError else: error_message = response.text['message'] logging.error(error_message)