aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--slack/slack_message.py22
-rw-r--r--slack/slack_workspace.py5
2 files changed, 21 insertions, 6 deletions
diff --git a/slack/slack_message.py b/slack/slack_message.py
index 4a45151..438166f 100644
--- a/slack/slack_message.py
+++ b/slack/slack_message.py
@@ -187,8 +187,13 @@ class PendingMessageItem:
try:
conversation = await self.message.workspace.conversations[self.item_id]
name = await conversation.name_with_prefix("short_name_without_padding")
- except SlackApiError as e:
- if e.response["error"] == "channel_not_found":
+ except (SlackApiError, SlackError) as e:
+ if (
+ isinstance(e, SlackApiError)
+ and e.response["error"] == "channel_not_found"
+ or isinstance(e, SlackError)
+ and e.error == "item_not_found"
+ ):
name = (
f"#{self.fallback_name}"
if self.fallback_name
@@ -207,8 +212,13 @@ class PendingMessageItem:
elif self.item_type == "user":
try:
user = await self.message.workspace.users[self.item_id]
- except SlackApiError as e:
- if e.response["error"] == "user_not_found":
+ except (SlackApiError, SlackError) as e:
+ if (
+ isinstance(e, SlackApiError)
+ and e.response["error"] == "user_not_found"
+ or isinstance(e, SlackError)
+ and e.error == "item_not_found"
+ ):
name = (
f"@{self.fallback_name}"
if self.fallback_name
@@ -235,7 +245,9 @@ class PendingMessageItem:
isinstance(e, SlackApiError)
and e.response["error"] == "invalid_auth"
or isinstance(e, SlackError)
- and e.error == "usergroup_not_found"
+ and (
+ e.error == "usergroup_not_found" or e.error == "item_not_found"
+ )
):
name = (
self.fallback_name if self.fallback_name else f"@{self.item_id}"
diff --git a/slack/slack_workspace.py b/slack/slack_workspace.py
index 0fab5b2..8c0f9a6 100644
--- a/slack/slack_workspace.py
+++ b/slack/slack_workspace.py
@@ -85,7 +85,10 @@ class SlackItem(
) -> SlackItemClass:
if items_info_task:
items_info = await items_info_task
- return self._create_item_from_info(items_info[item_id])
+ item = items_info.get(item_id)
+ if item is None:
+ raise SlackError(self.workspace, "item_not_found")
+ return self._create_item_from_info(item)
else:
return await self._item_class.create(self.workspace, item_id)