diff --git a/elementary/messages/messaging_integrations/slack_web.py b/elementary/messages/messaging_integrations/slack_web.py index 362ee2edd..5fd2bfcf3 100644 --- a/elementary/messages/messaging_integrations/slack_web.py +++ b/elementary/messages/messaging_integrations/slack_web.py @@ -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 diff --git a/tests/unit/messages/messaging_integrations/test_slack_web.py b/tests/unit/messages/messaging_integrations/test_slack_web.py index d5f2e73d4..a9951c6c4 100644 --- a/tests/unit/messages/messaging_integrations/test_slack_web.py +++ b/tests/unit/messages/messaging_integrations/test_slack_web.py @@ -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) @@ -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