From f83ddd59bd5892f6e32de4e3e6927d203b69b78c Mon Sep 17 00:00:00 2001 From: Ben Date: Mon, 22 Dec 2025 05:57:26 +0000 Subject: [PATCH] fix: handle non-JSON responses (logs endpoint returns text) - Check content-type header before parsing as JSON - Return raw text wrapped in dict for non-JSON responses - Also accept both GITEA_URL and GITEA_HOST env vars --- server.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/server.py b/server.py index adfd695..983be97 100644 --- a/server.py +++ b/server.py @@ -62,7 +62,7 @@ class GiteaClient: endpoint: str, params: dict[str, Any] | None = None, json_body: dict[str, Any] | None = None, - ) -> dict[str, Any]: + ) -> dict[str, Any] | list[Any]: """Execute an API request to Gitea.""" client = await self._get_client() url = f"{self.api_url}{endpoint}" @@ -79,7 +79,13 @@ class GiteaClient: if response.status_code == 204: return {"status": "success", "message": "No content"} - return response.json() + # Try to parse as JSON, fall back to text for endpoints like /logs + content_type = response.headers.get("content-type", "") + if "application/json" in content_type: + return response.json() + else: + # Return raw text wrapped in a dict for non-JSON responses + return {"content": response.text, "content_type": content_type} except httpx.HTTPStatusError as e: return { "error": True,