diff --git a/apps/chat/integrations/mattermost/client.py b/apps/chat/integrations/mattermost/client.py index 3afb81c..e94cb1e 100644 --- a/apps/chat/integrations/mattermost/client.py +++ b/apps/chat/integrations/mattermost/client.py @@ -72,12 +72,22 @@ class MattermostClient: def _ensure_team_member(self, mm_user_id: str) -> None: if not self._team_id: return + try: + self._driver.teams.get_team_member(self._team_id, mm_user_id) + return # already a member + except ResourceNotFound: + pass + except Exception as exc: + raise MattermostError(f"Team membership lookup failed: {exc}") from exc + try: self._driver.teams.add_user_to_team( self._team_id, options={"team_id": self._team_id, "user_id": mm_user_id} ) - except Exception: - pass # already a member or team not configured — not fatal + except Exception as exc: + raise MattermostError( + f"Adding user {mm_user_id} to team failed: {exc}" + ) from exc def get_or_create_user(self, user_id: UUID) -> str: """