Skip to content

Commit 0ac90d9

Browse files
johnyrahulclaude
andcommitted
fix: guard whisper_detail error path against non-JSON responses
Handle empty body and non-JSON error responses consistently with whisper_status, raising LLMWhispererClientException instead of letting json.JSONDecodeError propagate. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 258b396 commit 0ac90d9

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

src/unstract/llmwhisperer/client_v2.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,17 @@ def whisper_detail(self, whisper_hash: str) -> Any:
353353
prepared = req.prepare()
354354
response = self._send_request(prepared)
355355
if response.status_code != 200:
356-
err = json.loads(response.text)
356+
if not (response.text or "").strip():
357+
raise LLMWhispererClientException(
358+
"API error: empty response body", response.status_code
359+
)
360+
try:
361+
err = json.loads(response.text)
362+
except json.JSONDecodeError as e:
363+
response_preview = response.text[:500] + "..." if len(response.text) > 500 else response.text
364+
raise LLMWhispererClientException(
365+
f"API error: non-JSON response - {response_preview}", response.status_code
366+
) from e
357367
err["status_code"] = response.status_code
358368
raise LLMWhispererClientException(err)
359369
return json.loads(response.text)

0 commit comments

Comments
 (0)