Skip to content
This repository was archived by the owner on Sep 3, 2025. It is now read-only.

Commit 6292142

Browse files
authored
Better error handling when creating executive reports via Slack plugin (#2923)
1 parent b326abe commit 6292142

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

src/dispatch/plugins/dispatch_slack/incident/interactive.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import logging
22
from datetime import datetime
3-
import inspect
43
from typing import Any
5-
import time
64

75
import pytz
86
from blockkit import (
@@ -1718,34 +1716,46 @@ def handle_report_executive_submission_event(
17181716
form_data: dict,
17191717
user: DispatchUser,
17201718
) -> None:
1721-
"""Handles the report executive submission"""
1719+
"""Handles the report executive submission."""
17221720
ack_report_executive_submission_event(ack=ack)
1721+
1722+
incident = incident_service.get(db_session=db_session, incident_id=context["subject"].id)
1723+
17231724
executive_report_in = ExecutiveReportCreate(
17241725
current_status=form_data[ReportExecutiveBlockIds.current_status],
17251726
overview=form_data[ReportExecutiveBlockIds.overview],
17261727
next_steps=form_data[ReportExecutiveBlockIds.next_steps],
17271728
)
17281729

1729-
incident = incident_service.get(db_session=db_session, incident_id=context["subject"].id)
1730-
17311730
executive_report = report_flows.create_executive_report(
17321731
user_email=user.email,
1733-
incident_id=context["subject"].id,
1732+
incident_id=incident.id,
17341733
executive_report_in=executive_report_in,
17351734
organization_slug=context["subject"].organization_slug,
17361735
)
17371736

1738-
modal = Modal(
1739-
title="Executive Report",
1740-
blocks=[
1737+
blocks = []
1738+
if executive_report and incident.notifications_group:
1739+
blocks = [
17411740
Section(text="Creating executive report... Success!"),
17421741
Section(
17431742
text=f"The executive report document has been created and can be found in the incident storage here: {executive_report.document.weblink}"
17441743
),
17451744
Section(
1746-
text=f"The executive report has been emailed to the incident notifications group ({incident.notifications_group.email}).",
1745+
text=f"The executive report has been emailed to the incident notifications group: {incident.notifications_group.email}",
17471746
),
1748-
],
1747+
]
1748+
else:
1749+
blocks = [
1750+
Section(text="Creating executive report... Failed!"),
1751+
Section(
1752+
text="The executive report document was not created successfully or the incident notifications group does not exist."
1753+
),
1754+
]
1755+
1756+
modal = Modal(
1757+
title="Executive Report",
1758+
blocks=blocks,
17491759
close="Close",
17501760
).build()
17511761

0 commit comments

Comments
 (0)