Fix error path when channel is not found

This commit is contained in:
Midgard 2023-10-27 13:59:15 +02:00
parent e98bd8c507
commit 0249a58a36
Signed by: midgard
GPG key ID: 511C112F1331BBB4

View file

@ -128,17 +128,23 @@ def predicate_for_query(query: str):
def resolve_team(mm_api: mattermost.MMApi, query: str) -> Optional[Dict]: def resolve_team(mm_api: mattermost.MMApi, query: str) -> Optional[Dict]:
return first(filter( return first(
filter(
predicate_for_query(query), predicate_for_query(query),
mm_api.get_teams() mm_api.get_teams()
)) ),
None
)
def resolve_channel(mm_api: mattermost.MMApi, team_id: str, query: str) -> Optional[Dict]: def resolve_channel(mm_api: mattermost.MMApi, team_id: str, query: str) -> Optional[Dict]:
return first(filter( return first(
filter(
predicate_for_query(query), predicate_for_query(query),
mm_api.get_team_channels(team_id) mm_api.get_team_channels(team_id)
)) ),
None
)
def resolve_team_channel(mm_api: mattermost.MMApi, query: str) -> Dict: def resolve_team_channel(mm_api: mattermost.MMApi, query: str) -> Dict:
@ -156,7 +162,7 @@ def resolve_team_channel(mm_api: mattermost.MMApi, query: str) -> Dict:
else: else:
channel = resolve_channel(mm_api, team["id"], query_parts[1]) channel = resolve_channel(mm_api, team["id"], query_parts[1])
if not channel: if not channel:
return NotFound("channel", query_parts[1]) raise NotFound("channel", query_parts[1])
return team, channel return team, channel