Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom error message for expired trigger ids #2909

Merged
merged 5 commits into from
Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/dispatch/plugins/dispatch_slack/bolt.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from slack_bolt import Ack, BoltContext, BoltRequest, Respond
from slack_bolt.response import BoltResponse
from slack_sdk.web.client import WebClient
from slack_sdk.errors import SlackApiError
from sqlalchemy.orm import Session

from dispatch.auth.models import DispatchUser
Expand All @@ -19,6 +20,7 @@
build_bot_not_present_message,
build_context_error_message,
build_role_error_message,
build_slack_api_error_message,
build_unexpected_error_message,
)
from .middleware import (
Expand Down Expand Up @@ -111,6 +113,11 @@ def build_and_log_error(
client, payload["command"], context["conversations"]
)
logger.info(error)

elif isinstance(error, SlackApiError):
message = build_slack_api_error_message(error)
logger.exception(error)

else:
guid = str(uuid.uuid4())
message = build_unexpected_error_message(guid)
Expand Down
2 changes: 1 addition & 1 deletion src/dispatch/plugins/dispatch_slack/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def dispatch(self, *args, **kwargs):
if exclude := f["exclude"]:
subtype: str = kwargs.get("body", {}).get("event", {}).get("subtype", "")
if subtype in exclude.get("subtype", []):
log.debug(f"Skipping a dispatched function ({f['name']})")
log.debug(f"Skipping dispatched function ({f['name']})")
continue

try:
Expand Down
9 changes: 9 additions & 0 deletions src/dispatch/plugins/dispatch_slack/messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from blockkit import Actions, Button, Context, Divider, MarkdownText, Section
from slack_sdk.web.client import WebClient
from slack_sdk.errors import SlackApiError

from dispatch.messaging.strings import (
EVERGREEN_REMINDER_DESCRIPTION,
Expand Down Expand Up @@ -158,6 +159,14 @@ def build_bot_not_present_message(client: WebClient, command: str, conversations
return message


def build_slack_api_error_message(error: SlackApiError) -> str:
return (
"Sorry, the request to Slack timed out. Try running your command again."
if error.response.get("error") == "expired_trigger_id"
else "Sorry, we've run into an unexpected error with Slack."
)


def build_unexpected_error_message(guid: str) -> str:
message = f"""Sorry, we've run into an unexpected error. \
For help please reach out to your Dispatch admins and provide them with the following token: `{guid}`"""
Expand Down