diff --git a/zulip_botserver/zulip_botserver/server.py b/zulip_botserver/zulip_botserver/server.py index c6a9a00..04b423c 100644 --- a/zulip_botserver/zulip_botserver/server.py +++ b/zulip_botserver/zulip_botserver/server.py @@ -140,7 +140,7 @@ bots_config = {} # type: Dict[str, Dict[str, str]] @app.route('/', methods=['POST']) -def handle_bot() -> Union[str, BadRequest, Unauthorized]: +def handle_bot() -> str: event = request.get_json(force=True) for bot_name, config in bots_config.items(): if config['email'] == event['bot_email']: @@ -148,13 +148,13 @@ def handle_bot() -> Union[str, BadRequest, Unauthorized]: bot_config = config break else: - return BadRequest("Cannot find a bot with email {} in the Botserver " - "configuration file. Do the emails in your botserverrc " - "match the bot emails on the server?".format(event['bot_email'])) + raise BadRequest("Cannot find a bot with email {} in the Botserver " + "configuration file. Do the emails in your botserverrc " + "match the bot emails on the server?".format(event['bot_email'])) if bot_config['token'] != event['token']: - return Unauthorized("Request token does not match token found for bot {} in the " - "Botserver configuration file. Do the outgoing webhooks in " - "Zulip point to the right Botserver?".format(event['bot_email'])) + raise Unauthorized("Request token does not match token found for bot {} in the " + "Botserver configuration file. Do the outgoing webhooks in " + "Zulip point to the right Botserver?".format(event['bot_email'])) lib_module = app.config.get("BOTS_LIB_MODULES", {})[bot] bot_handler = app.config.get("BOT_HANDLERS", {})[bot] message_handler = app.config.get("MESSAGE_HANDLERS", {})[bot]