Skip to content

Commit fab4279

Browse files
Add exceptions missing from top-level package (#1045)
* Expose missing exceptions: CloseError, ConnectError, ReadError, WriteError * Lint
1 parent 6cf9039 commit fab4279

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

httpx/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
from ._client import AsyncClient, Client
55
from ._config import PoolLimits, Proxy, Timeout
66
from ._exceptions import (
7+
CloseError,
8+
ConnectError,
79
ConnectTimeout,
810
CookieConflict,
911
DecodingError,
@@ -14,13 +16,17 @@
1416
PoolTimeout,
1517
ProtocolError,
1618
ProxyError,
19+
ReadError,
1720
ReadTimeout,
21+
RedirectError,
1822
RequestBodyUnavailable,
1923
RequestNotRead,
2024
ResponseClosed,
2125
ResponseNotRead,
2226
StreamConsumed,
27+
StreamError,
2328
TooManyRedirects,
29+
WriteError,
2430
WriteTimeout,
2531
)
2632
from ._models import URL, Cookies, Headers, QueryParams, Request, Response
@@ -54,6 +60,8 @@
5460
"PoolLimits",
5561
"Proxy",
5662
"Timeout",
63+
"CloseError",
64+
"ConnectError",
5765
"ConnectTimeout",
5866
"CookieConflict",
5967
"DecodingError",
@@ -63,14 +71,18 @@
6371
"NotRedirectResponse",
6472
"PoolTimeout",
6573
"ProtocolError",
74+
"ReadError",
6675
"ReadTimeout",
76+
"RedirectError",
6777
"RequestBodyUnavailable",
6878
"ResponseClosed",
6979
"ResponseNotRead",
7080
"RequestNotRead",
7181
"StreamConsumed",
82+
"StreamError",
7283
"ProxyError",
7384
"TooManyRedirects",
85+
"WriteError",
7486
"WriteTimeout",
7587
"URL",
7688
"URLLib3Transport",

tests/test_exceptions.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import pytest
2+
3+
import httpx
4+
5+
6+
def test_httpx_exceptions_exposed() -> None:
7+
"""
8+
All exception classes defined in `httpx._exceptions`
9+
are exposed as public API.
10+
"""
11+
12+
not_exposed = [
13+
value
14+
for name, value in vars(httpx._exceptions).items()
15+
if isinstance(value, type)
16+
and issubclass(value, Exception)
17+
and not hasattr(httpx, name)
18+
]
19+
20+
if not_exposed:
21+
pytest.fail(f"Unexposed HTTPX exceptions: {not_exposed}")

0 commit comments

Comments
 (0)