404
>>> not_found.raise_for_status()
Traceback (most recent call last):
- File "/Users/tomchristie/GitHub/encode/httpcore/httpx/models.py", line 776, in raise_for_status
- raise HTTPError(message)
-httpx.HTTPError: 404 Not Found
+ File "/Users/tomchristie/GitHub/encode/httpcore/httpx/models.py", line 837, in raise_for_status
+ raise HTTPStatusError(message, response=self)
+httpx._exceptions.HTTPStatusError: 404 Client Error: Not Found for url: https://httpbin.org/status/404
+For more information check: https://httpstatuses.com/404
```
Any successful response codes will simply return `None` rather than raising an exception.
CookieConflict,
DecodingError,
HTTPError,
+ HTTPStatusError,
InvalidURL,
NetworkError,
NotRedirectResponse,
"CookieConflict",
"DecodingError",
"HTTPError",
+ "HTTPStatusError",
"InvalidURL",
"NetworkError",
"NotRedirectResponse",
"""
+class HTTPStatusError(HTTPError):
+ """
+ Response sent an error HTTP status.
+ """
+
+ def __init__(self, *args: typing.Any, response: "Response") -> None:
+ super().__init__(*args)
+ self._request = response.request
+ self.response = response
+
+
# Redirect exceptions...
)
from ._exceptions import (
CookieConflict,
- HTTPError,
+ HTTPStatusError,
InvalidURL,
NotRedirectResponse,
RequestNotRead,
def raise_for_status(self) -> None:
"""
- Raise the `HTTPError` if one occurred.
+ Raise the `HTTPStatusError` if one occurred.
"""
message = (
"{0.status_code} {error_type}: {0.reason_phrase} for url: {0.url}\n"
if StatusCode.is_client_error(self.status_code):
message = message.format(self, error_type="Client Error")
- raise HTTPError(message, response=self)
+ raise HTTPStatusError(message, response=self)
elif StatusCode.is_server_error(self.status_code):
message = message.format(self, error_type="Server Error")
- raise HTTPError(message, response=self)
+ raise HTTPStatusError(message, response=self)
def json(self, **kwargs: typing.Any) -> typing.Any:
if self.charset_encoding is None and self.content and len(self.content) > 3:
)
if 400 <= status_code < 600:
- with pytest.raises(httpx.HTTPError) as exc_info:
+ with pytest.raises(httpx.HTTPStatusError) as exc_info:
response.raise_for_status()
assert exc_info.value.response == response
else:
"GET", server.url.copy_with(path=f"/status/{status_code}")
)
if 400 <= status_code < 600:
- with pytest.raises(httpx.HTTPError) as exc_info:
+ with pytest.raises(httpx.HTTPStatusError) as exc_info:
response.raise_for_status()
assert exc_info.value.response == response
assert exc_info.value.request.url.path == f"/status/{status_code}"