tomchristie: We could have a `.is_success` property, but folks *might* expect that to be equivelent to `100 <= response.status_code <= 399`... Or am I being overly cautious there?
florimondmanca: Nice about `.is_error`.

What do we think about `.is_200_ok`?
tomchristie: Nah, that'd just be cleaner as `response.status_code == 200`

Having `response.is_error` is sensible, because it's the same check as `response.raise_for_status(...)`, but without raising an exception.
diff --git a/docs/compatibility.md b/docs/compatibility.md
index a95c12c..d652a0a 100644
--- a/docs/compatibility.md
+++ b/docs/compatibility.md
@@ -14,6 +14,7 @@ to the API in our own documentation. The following exceptions apply:
 but also provide lower-cased versions for API compatibility with `requests`.
 * `stream=True`. - Streaming responses provide the `.stream()` and `.raw()` byte iterator interfaces, rather than the `.iter_content()` method and the `.raw` socket interface.
 * `.get`, `.delete`, `.head`, `.options` -  These methods do not support `files`, `data`, or `json` arguments. Use `.request` if you need to need to send data using these http methods.
+* We don't support `response.is_ok` since the naming is ambiguous there, and might incorrectly imply an equivalence to `response.status_code == codes.OK`. Instead we provide an `.is_error` property.
 
 ## Advanced Usage
 
diff --git a/httpx/models.py b/httpx/models.py
index e703e2d..5469efc 100644
--- a/httpx/models.py
+++ b/httpx/models.py
@@ -846,6 +846,10 @@ class Response:
 
         return self._decoder
 
+    @property
+    def is_error(self) -> bool:
+        return StatusCode.is_error(self.status_code)
+
     @property
     def is_redirect(self) -> bool:
         return StatusCode.is_redirect(self.status_code) and "location" in self.headers
@@ -861,11 +865,9 @@ class Response:
 
         if StatusCode.is_client_error(self.status_code):
             message = message.format(self, error_type="Client Error")
+            raise HTTPError(message, response=self)
         elif StatusCode.is_server_error(self.status_code):
             message = message.format(self, error_type="Server Error")
-        else:
-            message = ""
-        if message:
             raise HTTPError(message, response=self)
 
     def json(self, **kwargs: typing.Any) -> typing.Union[dict, list]:
diff --git a/httpx/status_codes.py b/httpx/status_codes.py
index 3be26ca..eda7c56 100644
--- a/httpx/status_codes.py
+++ b/httpx/status_codes.py
@@ -49,6 +49,10 @@ class StatusCode(IntEnum):
             StatusCode.PERMANENT_REDIRECT,
         )
 
+    @classmethod
+    def is_error(cls, value: int) -> bool:
+        return 400 <= value <= 599
+
     @classmethod
     def is_client_error(cls, value: int) -> bool:
         return 400 <= value <= 499

Add equivalent to requests.response `ok` property
Hey there, I'm wondering do we have some equivalent of `requests.response:ok` property in `httpx` library? If no, Is it planning to be added sometime in the future? thx!
diff --git a/tests/models/test_responses.py b/tests/models/test_responses.py
index 012d2b7..e7be487 100644
--- a/tests/models/test_responses.py
+++ b/tests/models/test_responses.py
@@ -23,6 +23,7 @@ def test_response():
     assert response.reason_phrase == "OK"
     assert response.text == "Hello, world!"
     assert response.elapsed == datetime.timedelta(0)
+    assert not response.is_error
 
 
 def test_response_repr():

pip install -e .
parse_log_pytest
requirements.txt
3.9
requirements.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
aspy.refactor-imports==3.0.2
attrs==25.3.0
autoflake==2.3.1
babel==2.17.0
backrefs==5.8
black==25.1.0
brotlipy==0.7.0
certifi==2025.1.31
cffi==1.17.1
chardet==3.0.4
charset-normalizer==3.4.1
click==8.1.8
colorama==0.4.6
coverage==7.8.0
cryptography==44.0.2
exceptiongroup==1.2.2
flake8==7.2.0
flake8-bugbear==24.12.12
flake8-pie==0.16.0
ghp-import==2.1.0
h11==0.8.1
h2==3.2.0
hpack==3.0.0
hstspreload==2025.1.1
-e git+https://github.com/encode/httpx.git@9df76ccfe97d4df57a5dad832ef137d68282b432#egg=httpx
hyperframe==5.2.0
idna==2.10
importlib_metadata==8.6.1
iniconfig==2.1.0
isort==6.0.1
Jinja2==3.1.6
Markdown==3.7
MarkupSafe==3.0.2
mccabe==0.7.0
mergedeep==1.3.4
mkautodoc==0.2.0
mkdocs==1.6.1
mkdocs-get-deps==0.2.0
mkdocs-material==9.6.10
mkdocs-material-extensions==1.3.1
mypy==1.15.0
mypy-extensions==1.0.0
outcome==1.3.0.post0
packaging==24.2
paginate==0.5.7
pathspec==0.12.1
platformdirs==4.3.7
pluggy==1.5.0
pycodestyle==2.13.0
pycparser==2.22
pyflakes==3.3.2
Pygments==2.19.1
pymdown-extensions==10.14.3
pytest==8.3.5
pytest-asyncio==0.26.0
pytest-cov==6.0.0
pytest-trio==0.8.0
python-dateutil==2.9.0.post0
PyYAML==6.0.2
pyyaml_env_tag==0.1
requests==2.32.3
rfc3986==1.5.0
seed-isort-config==2.2.0
six==1.17.0
sniffio==1.3.1
sortedcontainers==2.4.0
tomli==2.2.1
trio==0.29.0
trustme==1.2.1
typing_extensions==4.13.0
urllib3==2.3.0
uvicorn==0.34.0
watchdog==6.0.0
zipp==3.21.0

name: httpx
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=3.0.16=h5eee18b_0
  - pip=25.0=py39h06a4308_0
  - python=3.9.21=he870216_1
  - readline=8.2=h5eee18b_0
  - setuptools=75.8.0=py39h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - tzdata=2025a=h04d1e81_0
  - wheel=0.45.1=py39h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - aspy-refactor-imports==3.0.2
      - attrs==25.3.0
      - autoflake==2.3.1
      - babel==2.17.0
      - backrefs==5.8
      - black==25.1.0
      - brotlipy==0.7.0
      - certifi==2025.1.31
      - cffi==1.17.1
      - chardet==3.0.4
      - charset-normalizer==3.4.1
      - click==8.1.8
      - colorama==0.4.6
      - coverage==7.8.0
      - cryptography==44.0.2
      - exceptiongroup==1.2.2
      - flake8==7.2.0
      - flake8-bugbear==24.12.12
      - flake8-pie==0.16.0
      - ghp-import==2.1.0
      - h11==0.8.1
      - h2==3.2.0
      - hpack==3.0.0
      - hstspreload==2025.1.1
      - hyperframe==5.2.0
      - idna==2.10
      - importlib-metadata==8.6.1
      - iniconfig==2.1.0
      - isort==6.0.1
      - jinja2==3.1.6
      - markdown==3.7
      - markupsafe==3.0.2
      - mccabe==0.7.0
      - mergedeep==1.3.4
      - mkautodoc==0.2.0
      - mkdocs==1.6.1
      - mkdocs-get-deps==0.2.0
      - mkdocs-material==9.6.10
      - mkdocs-material-extensions==1.3.1
      - mypy==1.15.0
      - mypy-extensions==1.0.0
      - outcome==1.3.0.post0
      - packaging==24.2
      - paginate==0.5.7
      - pathspec==0.12.1
      - platformdirs==4.3.7
      - pluggy==1.5.0
      - pycodestyle==2.13.0
      - pycparser==2.22
      - pyflakes==3.3.2
      - pygments==2.19.1
      - pymdown-extensions==10.14.3
      - pytest==8.3.5
      - pytest-asyncio==0.26.0
      - pytest-cov==6.0.0
      - pytest-trio==0.8.0
      - python-dateutil==2.9.0.post0
      - pyyaml==6.0.2
      - pyyaml-env-tag==0.1
      - requests==2.32.3
      - rfc3986==1.5.0
      - seed-isort-config==2.2.0
      - six==1.17.0
      - sniffio==1.3.1
      - sortedcontainers==2.4.0
      - tomli==2.2.1
      - trio==0.29.0
      - trustme==1.2.1
      - typing-extensions==4.13.0
      - urllib3==2.3.0
      - uvicorn==0.34.0
      - watchdog==6.0.0
      - zipp==3.21.0
prefix: /opt/conda/envs/httpx

tests/models/test_responses.py::test_response
tests/models/test_responses.py::test_response_repr tests/models/test_responses.py::test_response_content_type_encoding tests/models/test_responses.py::test_response_autodetect_encoding tests/models/test_responses.py::test_response_fallback_to_autodetect tests/models/test_responses.py::test_response_default_text_encoding tests/models/test_responses.py::test_response_default_encoding tests/models/test_responses.py::test_response_non_text_encoding tests/models/test_responses.py::test_response_set_explicit_encoding tests/models/test_responses.py::test_response_force_encoding tests/models/test_responses.py::test_read_response tests/models/test_responses.py::test_raw_interface tests/models/test_responses.py::test_stream_interface tests/models/test_responses.py::test_stream_text tests/models/test_responses.py::test_stream_interface_after_read tests/models/test_responses.py::test_streaming_response tests/models/test_responses.py::test_cannot_read_after_stream_consumed tests/models/test_responses.py::test_cannot_read_after_response_closed tests/models/test_responses.py::test_unknown_status_code tests/models/test_responses.py::test_json_with_specified_encoding tests/models/test_responses.py::test_json_with_options tests/models/test_responses.py::test_json_without_specified_encoding tests/models/test_responses.py::test_json_without_specified_encoding_decode_error tests/models/test_responses.py::test_link_headers[headers0-expected0] tests/models/test_responses.py::test_link_headers[headers1-expected1]
docs/compatibility.md httpx/status_codes.py httpx/models.py
docs/compatibility.md httpx/status_codes.py httpx/models.py