Skip to content

Commit

Permalink
fix(slack): handle missing client_msg_id more graceful
Browse files Browse the repository at this point in the history
  • Loading branch information
janaka committed May 1, 2024
1 parent 1c56ed9 commit ac7a03f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions web/api/integration/slack/slack_event_handler_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ def filter_duplicate_event_middleware(ack: Ack, body: dict, next_: Callable) ->
def persist_message_middleware(body: dict, next_: Callable) -> None:
"""Middleware to persist messages."""
span = trace.get_current_span()
client_msg_id = body["event"]["client_msg_id"]
print(json.dumps(body, indent=4))
client_msg_id = body["event"].get("client_msg_id")
type_ = body["event"]["type"]
channel = body["event"]["channel"]
team = body["event"]["team"]
Expand All @@ -79,7 +80,7 @@ def persist_message_middleware(body: dict, next_: Callable) -> None:

span.set_attributes(
attributes={
"event__client_msg_id": client_msg_id,
"event__client_msg_id": client_msg_id or "None",
"event__type": type_,
"event__ts": ts,
"event__parent_thread_ts": thread_ts or "None",
Expand All @@ -90,6 +91,7 @@ def persist_message_middleware(body: dict, next_: Callable) -> None:
"org_id": org_id or "None",
}
)

if org_id is None:
span.record_exception(ValueError(f"No Org ID found for Slack team ID '{team}'"))
span.set_status(trace.StatusCode.ERROR, "No Org ID found")
Expand Down

0 comments on commit ac7a03f

Please sign in to comment.