botserver: Raise exceptions rather than returning them.
This commit is contained in:
parent
fca2404b46
commit
520a004b85
|
@ -140,7 +140,7 @@ bots_config = {} # type: Dict[str, Dict[str, str]]
|
||||||
|
|
||||||
|
|
||||||
@app.route('/', methods=['POST'])
|
@app.route('/', methods=['POST'])
|
||||||
def handle_bot() -> Union[str, BadRequest, Unauthorized]:
|
def handle_bot() -> str:
|
||||||
event = request.get_json(force=True)
|
event = request.get_json(force=True)
|
||||||
for bot_name, config in bots_config.items():
|
for bot_name, config in bots_config.items():
|
||||||
if config['email'] == event['bot_email']:
|
if config['email'] == event['bot_email']:
|
||||||
|
@ -148,13 +148,13 @@ def handle_bot() -> Union[str, BadRequest, Unauthorized]:
|
||||||
bot_config = config
|
bot_config = config
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
return BadRequest("Cannot find a bot with email {} in the Botserver "
|
raise BadRequest("Cannot find a bot with email {} in the Botserver "
|
||||||
"configuration file. Do the emails in your botserverrc "
|
"configuration file. Do the emails in your botserverrc "
|
||||||
"match the bot emails on the server?".format(event['bot_email']))
|
"match the bot emails on the server?".format(event['bot_email']))
|
||||||
if bot_config['token'] != event['token']:
|
if bot_config['token'] != event['token']:
|
||||||
return Unauthorized("Request token does not match token found for bot {} in the "
|
raise Unauthorized("Request token does not match token found for bot {} in the "
|
||||||
"Botserver configuration file. Do the outgoing webhooks in "
|
"Botserver configuration file. Do the outgoing webhooks in "
|
||||||
"Zulip point to the right Botserver?".format(event['bot_email']))
|
"Zulip point to the right Botserver?".format(event['bot_email']))
|
||||||
lib_module = app.config.get("BOTS_LIB_MODULES", {})[bot]
|
lib_module = app.config.get("BOTS_LIB_MODULES", {})[bot]
|
||||||
bot_handler = app.config.get("BOT_HANDLERS", {})[bot]
|
bot_handler = app.config.get("BOT_HANDLERS", {})[bot]
|
||||||
message_handler = app.config.get("MESSAGE_HANDLERS", {})[bot]
|
message_handler = app.config.get("MESSAGE_HANDLERS", {})[bot]
|
||||||
|
|
Loading…
Reference in a new issue