Browse Source

Add handling for HTTP 502 response from Matrix server

master
Pēteris Caune 3 years ago
parent
commit
a127ab0f0c
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
2 changed files with 17 additions and 0 deletions
  1. +5
    -0
      hc/front/forms.py
  2. +12
    -0
      hc/front/tests/test_add_matrix.py

+ 5
- 0
hc/front/forms.py View File

@ -272,6 +272,11 @@ class AddMatrixForm(forms.Form):
"Matrix server returned status code 429 (Too Many Requests), "
"please try again later."
)
if r.status_code == 502:
raise forms.ValidationError(
"Matrix server returned status code 502 (Bad Gateway), "
"please try again later."
)
doc = r.json()
if "error" in doc:


+ 12
- 0
hc/front/tests/test_add_matrix.py View File

@ -20,6 +20,7 @@ class AddMatrixTestCase(BaseTestCase):
@patch("hc.front.forms.requests.post")
def test_it_works(self, mock_post):
mock_post.return_value.status_code = 200
mock_post.return_value.json.return_value = {"room_id": "fake-room-id"}
form = {"alias": "!foo:example.org"}
@ -49,6 +50,17 @@ class AddMatrixTestCase(BaseTestCase):
self.assertContains(r, "Matrix server returned status code 429")
self.assertFalse(Channel.objects.exists())
@patch("hc.front.forms.requests.post")
def test_it_handles_502(self, mock_post):
mock_post.return_value.status_code = 502
form = {"alias": "!foo:example.org"}
self.client.login(username="[email protected]", password="password")
r = self.client.post(self.url, form)
self.assertContains(r, "Matrix server returned status code 502")
self.assertFalse(Channel.objects.exists())
def test_it_requires_rw_access(self):
self.bobs_membership.role = "r"
self.bobs_membership.save()


Loading…
Cancel
Save