Skip to content

Commit 485b5d9

Browse files
committed
Don't reraise for HTTP exception
Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
1 parent 3e0e886 commit 485b5d9

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

src/connectrpc/_server_async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ async def __call__(
233233
)
234234
except Exception as e:
235235
await self._handle_error(e, ctx, send)
236-
if not isinstance(e, ConnectError):
236+
if not isinstance(e, (ConnectError, HTTPException)):
237237
raise
238238
return None
239239

test/test_errors.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
)
2020
from pyqwest.testing import ASGITransport, WSGITransport
2121

22+
from connectrpc._protocol import HTTPException
2223
from connectrpc.code import Code
2324
from connectrpc.errors import ConnectError
2425

@@ -517,3 +518,24 @@ def make_similar_hats(
517518
# Workaround https://github.com/curioswitch/pyqwest/pull/148
518519
# TODO: Remove after fix is released
519520
assert getattr(transport, "_app_exception", None) is None
521+
522+
523+
@pytest.mark.asyncio
524+
async def test_async_http_exception_not_reraised() -> None:
525+
class RaisingHaberdasher(Haberdasher):
526+
async def make_hat(self, request, ctx) -> NoReturn:
527+
raise HTTPException(status=HTTPStatus.INTERNAL_SERVER_ERROR, headers=[])
528+
529+
app = HaberdasherASGIApplication(RaisingHaberdasher())
530+
transport = ASGITransport(app)
531+
http_client = Client(transport)
532+
533+
async with HaberdasherClient(
534+
"http://localhost", timeout_ms=200, http_client=http_client
535+
) as client:
536+
with pytest.raises(ConnectError, match="Internal Server Error"):
537+
await client.make_hat(request=Size(inches=10))
538+
539+
# Workaround https://github.com/curioswitch/pyqwest/pull/148
540+
# TODO: Remove after fix is released
541+
assert getattr(transport, "_app_exception", None) is None

0 commit comments

Comments
 (0)