Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion miniflux.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down