From 894c4574508f8784074f08983e766155318439fc 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:08:33 -0700 Subject: [PATCH] fix(client): pass error reason to Exception base class Call super().__init__() with the error message so that str() and repr() on ClientError subclasses produce useful output. --- miniflux.py | 1 + tests/test_client.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/miniflux.py b/miniflux.py index 9d25c58..2157046 100644 --- a/miniflux.py +++ b/miniflux.py @@ -39,6 +39,7 @@ class ClientError(Exception): def __init__(self, response: requests.Response): self.status_code = response.status_code self._response = response + super().__init__(self.get_error_reason()) def get_error_reason(self) -> str: """ diff --git a/tests/test_client.py b/tests/test_client.py index c4aca63..d4a099d 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -48,6 +48,21 @@ def test_get_error_reason(self): self.assertEqual(error.status_code, 404) self.assertEqual(error.get_error_reason(), "some error") + def test_error_str_with_json_reason(self): + response = mock.Mock() + response.status_code = 404 + response.headers = {"Content-Type": "application/json"} + response.json.return_value = {"error_message": "feed not found"} + error = ResourceNotFound(response) + self.assertEqual(str(error), "feed not found") + + def test_error_str_without_json_reason(self): + response = mock.Mock() + response.status_code = 500 + response.headers = {} + error = ServerError(response) + self.assertEqual(str(error), "status_code=500") + def test_default_session_not_shared(self): client_one = miniflux.Client("http://localhost", api_key="token-one") client_two = miniflux.Client("http://localhost", api_key="token-two")