Skip to content

Commit e99ef8a

Browse files
authored
Prevented HttpConsumer from hiding exceptions (#1951)
1 parent 7254186 commit e99ef8a

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

channels/generic/http.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ async def http_request(self, message):
8181
await self.handle(b"".join(self.body))
8282
finally:
8383
await self.disconnect()
84-
raise StopConsumer()
84+
raise StopConsumer()
8585

8686
async def http_disconnect(self, message):
8787
"""

tests/test_generic_http.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,19 @@ async def handle(self, body):
3838
assert response["headers"] == [(b"Content-Type", b"application/json")]
3939

4040

41+
@pytest.mark.asyncio
42+
async def test_error():
43+
class TestConsumer(AsyncHttpConsumer):
44+
async def handle(self, body):
45+
raise AssertionError("Error correctly raised")
46+
47+
communicator = HttpCommunicator(TestConsumer(), "GET", "/")
48+
with pytest.raises(AssertionError) as excinfo:
49+
await communicator.get_response(timeout=0.05)
50+
51+
assert str(excinfo.value) == "Error correctly raised"
52+
53+
4154
@pytest.mark.asyncio
4255
async def test_per_scope_consumers():
4356
"""

0 commit comments

Comments
 (0)