bots: Improve error handling of yoda bot when the service is unavailable.

Frequent 503 errors throw index error exceptions which is misleading
to debug.
This commit is contained in:
Abhijeet Kaur 2017-08-01 01:00:42 +05:30 committed by Tim Abbott
parent a58fae5cab
commit 1e84e2eb5e

View file

@ -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)