forked from GithubBackups/healthchecks
Zulip integration returns more detailed error messages
This commit is contained in:
parent
8c7f3977e2
commit
5f2c20e46b
@ -826,3 +826,20 @@ class NotifyTestCase(BaseTestCase):
|
||||
args, kwargs = mock_post.call_args
|
||||
payload = kwargs["data"]
|
||||
self.assertIn("DOWN", payload["topic"])
|
||||
|
||||
@patch("hc.api.transports.requests.request")
|
||||
def test_zulip_returns_error(self, mock_post):
|
||||
definition = {
|
||||
"bot_email": "bot@example.org",
|
||||
"api_key": "fake-key",
|
||||
"mtype": "stream",
|
||||
"to": "general",
|
||||
}
|
||||
self._setup_data("zulip", json.dumps(definition))
|
||||
mock_post.return_value.status_code = 403
|
||||
mock_post.return_value.json.return_value = {"msg": "Nice try"}
|
||||
|
||||
self.channel.notify(self.check)
|
||||
|
||||
n = Notification.objects.first()
|
||||
self.assertEqual(n.error, 'Received status code 403 with a message: "Nice try"')
|
||||
|
@ -558,15 +558,16 @@ class MsTeams(HttpTransport):
|
||||
|
||||
class Zulip(HttpTransport):
|
||||
@classmethod
|
||||
def get_error(cls, r):
|
||||
def get_error(cls, response):
|
||||
try:
|
||||
doc = r.json()
|
||||
if "msg" in doc:
|
||||
return doc["msg"]
|
||||
m = response.json().get("msg")
|
||||
if m:
|
||||
code = response.status_code
|
||||
return f'Received status code {code} with a message: "{m}"'
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
return super().get_error(r)
|
||||
return super().get_error(response)
|
||||
|
||||
def notify(self, check):
|
||||
_, domain = self.channel.zulip_bot_email.split("@")
|
||||
|
Loading…
x
Reference in New Issue
Block a user