Skip to content

Commit 118264f

Browse files
authored
fix: gracefully handle users not found (#954)
* fix: gracefully handle users not found * chore: fmt
1 parent 061bc94 commit 118264f

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

app/integrations/slack/users.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,15 @@ def replace_users_emails_with_mention(text: str) -> str:
164164
email_pattern = r"[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}"
165165
matches = re.findall(email_pattern, text)
166166
for email in matches:
167-
response = client.users_lookupByEmail(email=email)
167+
try:
168+
response = client.users_lookupByEmail(email=email)
169+
# It's okay to catch all exceptions here since we don't want to fail the entire
170+
# operation if one email lookup fails.
171+
except Exception as e: # pylint: disable=broad-except
172+
logger.info(
173+
"replace_users_emails_with_mention_failed", extra={"error": str(e)}
174+
)
175+
response = None
168176
if response:
169177
user: dict = response.get("user", {})
170178
user_handle = user.get("id")

0 commit comments

Comments
 (0)