Skip to content

Commit

Permalink
feat: Throw if slack response is bad (#24646)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjackwhite authored Aug 29, 2024
1 parent f0f18b1 commit 102ec3c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion posthog/cdp/templates/slack/template_slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
});
if (res.status != 200 or not res.body.ok) {
print('Non-ok response:', res)
throw Error(f'Failed to post message to Slack: {res.status}: {res.body}');
}
""".strip(),
inputs_schema=[
Expand Down
13 changes: 9 additions & 4 deletions posthog/cdp/templates/slack/test_template_slack.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import pytest
from hogvm.python.utils import UncaughtHogVMException
from posthog.cdp.templates.helpers import BaseHogFunctionTemplateTest
from posthog.cdp.templates.slack.template_slack import template as template_slack

Expand Down Expand Up @@ -46,10 +48,13 @@ def test_function_works(self):

def test_function_prints_warning_on_bad_status(self):
self.mock_fetch_response = lambda *args: {"status": 400, "body": {"ok": True}} # type: ignore
self.run_function(self._inputs())
assert self.get_mock_print_calls() == [("Non-ok response:", {"status": 400, "body": {"ok": True}})]
with pytest.raises(UncaughtHogVMException) as e:
self.run_function(self._inputs())

assert e.value.message == "Failed to post message to Slack: 400: {'ok': true}"

def test_function_prints_warning_on_bad_body(self):
self.mock_fetch_response = lambda *args: {"status": 200, "body": {"ok": False}} # type: ignore
self.run_function(self._inputs())
assert self.get_mock_print_calls() == [("Non-ok response:", {"status": 200, "body": {"ok": False}})]
with pytest.raises(UncaughtHogVMException) as e:
self.run_function(self._inputs())
assert e.value.message == "Failed to post message to Slack: 200: {'ok': false}"

0 comments on commit 102ec3c

Please sign in to comment.