|
19 | 19 | ) |
20 | 20 | from pyqwest.testing import ASGITransport, WSGITransport |
21 | 21 |
|
| 22 | +from connectrpc._protocol import HTTPException |
22 | 23 | from connectrpc.code import Code |
23 | 24 | from connectrpc.errors import ConnectError |
24 | 25 |
|
@@ -517,3 +518,24 @@ def make_similar_hats( |
517 | 518 | # Workaround https://github.com/curioswitch/pyqwest/pull/148 |
518 | 519 | # TODO: Remove after fix is released |
519 | 520 | 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