From 6fb2bbaf2e6216e0a47af241f2f46a16bc1a8611 Mon Sep 17 00:00:00 2001 From: David Whittaker Date: Wed, 3 Jul 2024 10:05:01 -0700 Subject: [PATCH] Adds Slack error code skip retry --- src/dispatch/plugins/dispatch_slack/incident/interactive.py | 4 ++++ src/dispatch/plugins/dispatch_slack/service.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/dispatch/plugins/dispatch_slack/incident/interactive.py b/src/dispatch/plugins/dispatch_slack/incident/interactive.py index 64a70e8d3c5f..236e67b98c6a 100644 --- a/src/dispatch/plugins/dispatch_slack/incident/interactive.py +++ b/src/dispatch/plugins/dispatch_slack/incident/interactive.py @@ -815,6 +815,10 @@ def handle_after_hours_message( participant = participant_service.get_by_incident_id_and_email( db_session=db_session, incident_id=context["subject"].id, email=user.email ) + # handle no participant found + if not participant: + return + # get their timezone from slack try: owner_tz = (dispatch_slack_service.get_user_info_by_email(client, email=owner_email))["tz"] diff --git a/src/dispatch/plugins/dispatch_slack/service.py b/src/dispatch/plugins/dispatch_slack/service.py index 6ba63a911495..5512f94be6ca 100644 --- a/src/dispatch/plugins/dispatch_slack/service.py +++ b/src/dispatch/plugins/dispatch_slack/service.py @@ -104,7 +104,7 @@ def should_retry(exception: Exception) -> bool: match exception: case SlackApiError(): # Don't retry for re-adding users in channel. - if exception.response["error"] == SlackAPIErrorCode.USER_IN_CHANNEL: + if exception.response["error"] in [SlackAPIErrorCode.USER_IN_CHANNEL, SlackAPIErrorCode.ALREADY_IN_CHANNEL]: return False # Retry if it's not a fatal error return exception.response["error"] != SlackAPIErrorCode.FATAL_ERROR