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'])
|
||||
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,11 +148,11 @@ def handle_bot() -> Union[str, BadRequest, Unauthorized]:
|
|||
bot_config = config
|
||||
break
|
||||
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 "
|
||||
"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 "
|
||||
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]
|
||||
|
|
Loading…
Reference in a new issue