From e99ef8a3c3cb7f6a7232716457ea7d6c7a62927c Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sun, 10 Dec 2023 18:24:20 +0000 Subject: [PATCH] Prevented HttpConsumer from hiding exceptions (#1951) --- channels/generic/http.py | 2 +- tests/test_generic_http.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/channels/generic/http.py b/channels/generic/http.py index 8bbf35236..909e85704 100644 --- a/channels/generic/http.py +++ b/channels/generic/http.py @@ -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): """ diff --git a/tests/test_generic_http.py b/tests/test_generic_http.py index 85ecdd041..bfb889c0e 100644 --- a/tests/test_generic_http.py +++ b/tests/test_generic_http.py @@ -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(): """