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(): """