Skip to content
Myr

Keep HTTPError as a base class for .request() and .raise_for_status() (#1125)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Tom Christie · committed by GitHub · parent 0fb28e8 · Browse files · 1 file+48 added−33 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+48 added−33 removed

  • other:+48 added−33 removed

1 file+48 added−33 removed

modified:httpx/_exceptions.py+48 added-33 removed
1"""2Our exception hierarchy:34* HTTPError4* RequestError5 + TransportError6 - TimeoutException7 · ConnectTimeout8 · ReadTimeout9 · WriteTimeout10 · PoolTimeout11 - NetworkError12 · ConnectError13 · ReadError14 · WriteError15 · CloseError16 - ProxyError17 - ProtocolError18 + DecodingError19 + TooManyRedirects20 + RequestBodyUnavailable21 + InvalidURL22* HTTPStatusError5 x RequestError6 + TransportError7 - TimeoutException8 · ConnectTimeout9 · ReadTimeout10 · WriteTimeout11 · PoolTimeout12 - NetworkError13 · ConnectError14 · ReadError15 · WriteError16 · CloseError17 - ProtocolError18 - ProxyError19 + DecodingError20 + TooManyRedirects21 + RequestBodyUnavailable22 + InvalidURL23 x HTTPStatusError24* NotRedirectResponse25* CookieConflict26* StreamError26 + StreamConsumed27 + ResponseNotRead28 + RequestNotRead29 + ResponseClosed27 x StreamConsumed28 x ResponseNotRead29 x RequestNotRead30 x ResponseClosed31"""32import contextlib33import typing34
2 unmodified lines
37if typing.TYPE_CHECKING:38 from ._models import Request, Response # pragma: nocover394040class RequestError(Exception):41class HTTPError(Exception):42 """42 Base class for all exceptions that may occur when issuing a `.request()`.43 Base class for `RequestError` and `HTTPStatusError`.4445 Useful for `try...except` blocks when issuing a request,46 and then calling .raise_for_status().4748 For example:4950 try:51 response = httpx.get("https://www.example.com")52 response.raise_for_status()53 except httpx.HTTPError as exc:54 print(f"HTTP Exception for {exc.request.url} - {exc.message}")55 """5657 def __init__(self, message: str, *, request: "Request") -> None:58 super().__init__(message)59 self.request = request606162class RequestError(HTTPError):63 """64 Base class for all exceptions that may occur when issuing a `.request()`.65 """6667 def __init__(self, message: str, *, request: "Request") -> None:68 super().__init__(message, request=request)697071class TransportError(RequestError):72 """73 Base class for all exceptions that are mapped from the httpcore API.74 """
114 unmodified lines
189190# Client errors191192172class HTTPStatusError(Exception):193class HTTPStatusError(HTTPError):194 """195 Response sent an error HTTP status.196197 May be raised when calling `response.raise_for_status()`
1 unmodified line
199200 def __init__(201 self, message: str, *, request: "Request", response: "Response"202 ) -> None:182 super().__init__(message)183 self.request = request203 super().__init__(message, request=request)204 self.response = response205206207class NotRedirectResponse(Exception):
88 unmodified lines
296 )297 super().__init__(message)298299280# We're continuing to expose this earlier naming at the moment.281# It is due to be deprecated. Don't use it.282HTTPError = RequestError283284300@contextlib.contextmanager301def map_exceptions(302 mapping: typing.Mapping[typing.Type[Exception], typing.Type[Exception]],303 **kwargs: typing.Any,
36 unmodified lines