From 43689eb1dcb260e3f411e9951f2df8d48095b7cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Guillot?= <323546+fguillot@users.noreply.github.com> Date: Mon, 23 Mar 2026 21:28:53 -0700 Subject: [PATCH] fix(client): handle Content-Type with charset in error responses Use startswith instead of exact match for Content-Type check so that values like "application/json; charset=utf-8" are correctly recognized as JSON, allowing error messages to be extracted from the response body. --- miniflux.py | 3 ++- tests/test_client.py | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/miniflux.py b/miniflux.py index 05c2e93..9c1c2f6 100644 --- a/miniflux.py +++ b/miniflux.py @@ -49,7 +49,8 @@ def get_error_reason(self) -> str: str: The error message from the response body, or a default message if not available. """ default_reason = f"status_code={self.status_code}" - if self._response.headers.get("Content-Type") == "application/json": + content_type = self._response.headers.get("Content-Type", "") + if content_type.startswith("application/json"): result = self._response.json() if isinstance(result, dict): return result.get("error_message", default_reason) diff --git a/tests/test_client.py b/tests/test_client.py index d4a099d..39b11e2 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -89,6 +89,14 @@ def test_get_error_with_bad_response(self): self.assertEqual(error.status_code, 404) self.assertEqual(error.get_error_reason(), "status_code=404") + def test_get_error_reason_with_charset_in_content_type(self): + response = mock.Mock() + response.status_code = 400 + response.headers = {"Content-Type": "application/json; charset=utf-8"} + response.json.return_value = {"error_message": "invalid input"} + error = BadRequest(response) + self.assertEqual(error.get_error_reason(), "invalid input") + def test_get_error_reason_without_json_content_type(self): response = mock.Mock() response.status_code = 500