From baac1adf9d6b04acdc690444b8c07dfa053dfa16 Mon Sep 17 00:00:00 2001 From: Ike Johnson-Woods Date: Tue, 28 May 2024 20:21:24 +0800 Subject: [PATCH] Keycloak: raise Exception if group isn't found --- githubapp/keycloak.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/githubapp/keycloak.py b/githubapp/keycloak.py index f397b7c..e7b4a9a 100644 --- a/githubapp/keycloak.py +++ b/githubapp/keycloak.py @@ -52,7 +52,10 @@ def get_group_id(client: KeycloakAdmin = None): """ group = client.get_groups(query={"search": group_name}) group = client.get_groups(query={"search": group_name, "briefRepresentation": "true", "exact": "true"}) - return group[0]["id"] + try: + return group[0]["id"] + except IndexError as e: + raise Exception(f"Cannot find group {group_name} in Keycloak") def get_members(client: KeycloakAdmin = None, group_id: str = None): """