Skip to content
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
4 changes: 4 additions & 0 deletions elementary/messages/messaging_integrations/slack_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@ def _handle_send_err(self, err: SlackApiError, channel_name: str) -> NoReturn:
raise MessagingIntegrationDestinationNotFoundError(
f"Channel {channel_name} was not found by the Elementary app. Please add the app to the channel."
) from err
if err_type == "is_archived":
raise MessagingIntegrationDestinationNotFoundError(
f"Channel {channel_name} is archived. Please unarchive the channel or remove it from the alert settings."
) from err
raise MessagingIntegrationError(
f"Failed to send a message to channel - {channel_name} ({err_type})"
) from err
Expand Down
17 changes: 14 additions & 3 deletions tests/unit/messages/messaging_integrations/test_slack_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,21 @@ def test_send_raises_channel_not_found_error():
assert isinstance(exc_info.value, MessagingIntegrationError)


def test_send_raises_destination_not_found_for_archived_channel():
integration = _build_integration()
slack_error = SlackApiError("error", MagicMock(data={"error": "is_archived"}))
integration.client.chat_postMessage.side_effect = slack_error
with pytest.raises(MessagingIntegrationDestinationNotFoundError) as exc_info:
integration.send_message("alerts", HANDLE_MENTION_BODY)
assert "alerts" in str(exc_info.value)
assert "archived" in str(exc_info.value)
assert exc_info.value.__cause__ is slack_error


def test_send_raises_generic_error_for_other_slack_errors():
integration = _build_integration()
integration.client.chat_postMessage.side_effect = SlackApiError(
"error", MagicMock(data={"error": "is_archived"})
"error", MagicMock(data={"error": "ratelimited"})
)
with pytest.raises(MessagingIntegrationError) as exc_info:
integration.send_message("alerts", HANDLE_MENTION_BODY)
Expand Down Expand Up @@ -378,11 +389,11 @@ def test_channel_not_found_keeps_slack_error_as_cause():

def test_send_error_keeps_slack_error_code():
integration = _build_integration()
slack_error = SlackApiError("error", MagicMock(data={"error": "is_archived"}))
slack_error = SlackApiError("error", MagicMock(data={"error": "ratelimited"}))
integration.client.chat_postMessage.side_effect = slack_error
with pytest.raises(MessagingIntegrationError) as exc_info:
integration.send_message("alerts", HANDLE_MENTION_BODY)
assert "is_archived" in str(exc_info.value)
assert "ratelimited" in str(exc_info.value)
assert exc_info.value.__cause__ is slack_error


Expand Down
Loading