From fc1ea07450251845e345ef07ac51e69c95799dd5 Mon Sep 17 00:00:00 2001 From: Xubin Ren Date: Fri, 20 Mar 2026 11:09:21 +0000 Subject: [PATCH] fix(custom_provider): truncate raw error body to prevent huge HTML pages Made-with: Cursor --- nanobot/providers/custom_provider.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/nanobot/providers/custom_provider.py b/nanobot/providers/custom_provider.py index 35c5e71..3daa0cc 100644 --- a/nanobot/providers/custom_provider.py +++ b/nanobot/providers/custom_provider.py @@ -51,12 +51,12 @@ class CustomProvider(LLMProvider): try: return self._parse(await self._client.chat.completions.create(**kwargs)) except Exception as e: - # Extract raw response body from non-JSON API errors. - # JSONDecodeError.doc contains the original text (e.g. "unsupported model: xxx"); - # OpenAI APIError may carry it in response.text. + # JSONDecodeError.doc / APIError.response.text may carry the raw body + # (e.g. "unsupported model: xxx") which is far more useful than the + # generic "Expecting value …" message. Truncate to avoid huge HTML pages. body = getattr(e, "doc", None) or getattr(getattr(e, "response", None), "text", None) if body and body.strip(): - return LLMResponse(content=f"Error: {body.strip()}", finish_reason="error") + return LLMResponse(content=f"Error: {body.strip()[:500]}", finish_reason="error") return LLMResponse(content=f"Error: {e}", finish_reason="error") def _parse(self, response: Any) -> LLMResponse: