Skip to content

Commit

Permalink
Prevented HttpConsumer from hiding exceptions (#1951)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamchainz authored Dec 10, 2023
1 parent 7254186 commit e99ef8a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion channels/generic/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ async def http_request(self, message):
await self.handle(b"".join(self.body))
finally:
await self.disconnect()
raise StopConsumer()
raise StopConsumer()

async def http_disconnect(self, message):
"""
Expand Down
13 changes: 13 additions & 0 deletions tests/test_generic_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ async def handle(self, body):
assert response["headers"] == [(b"Content-Type", b"application/json")]


@pytest.mark.asyncio
async def test_error():
class TestConsumer(AsyncHttpConsumer):
async def handle(self, body):
raise AssertionError("Error correctly raised")

communicator = HttpCommunicator(TestConsumer(), "GET", "/")
with pytest.raises(AssertionError) as excinfo:
await communicator.get_response(timeout=0.05)

assert str(excinfo.value) == "Error correctly raised"


@pytest.mark.asyncio
async def test_per_scope_consumers():
"""
Expand Down

0 comments on commit e99ef8a

Please sign in to comment.