diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2023-10-15 19:19:03 +0200 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2024-02-18 11:32:54 +0100 |
commit | 0e4ac01dfd41a15eeb67de08ca788e82d3736a6f (patch) | |
tree | a76e93c28d64feec685bd19da10f26b8b802a719 /slack/slack_message.py | |
parent | 8065cf011b897de72330913c13aa11a7b3666368 (diff) | |
download | wee-slack-0e4ac01dfd41a15eeb67de08ca788e82d3736a6f.tar.gz |
Handle when some items are missing from the response
Diffstat (limited to 'slack/slack_message.py')
-rw-r--r-- | slack/slack_message.py | 22 |
1 files changed, 17 insertions, 5 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}" |