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")