mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-02-09 14:25:25 -05:00
fix: preserve non-dict error bodies as truncated strings
Addresses CodeRabbit feedback: non-dict error bodies (e.g., HTML error pages from proxies) were silently discarded, losing diagnostic info. Now returns truncated string representation instead of None.
This commit is contained in:
@@ -1843,9 +1843,17 @@ def _extract_api_error_details(error: Exception) -> dict[str, Any]:
|
||||
return details
|
||||
|
||||
|
||||
def _sanitize_error_body(body: Any, max_length: int = 2000) -> dict[str, Any] | None:
|
||||
def _sanitize_error_body(
|
||||
body: Any, max_length: int = 2000
|
||||
) -> dict[str, Any] | str | None:
|
||||
"""Extract only safe fields from error response body to avoid logging sensitive data."""
|
||||
if not isinstance(body, dict):
|
||||
# Non-dict bodies (e.g., HTML error pages) - return truncated string
|
||||
if body is not None:
|
||||
body_str = str(body)
|
||||
if len(body_str) > max_length:
|
||||
return body_str[:max_length] + "...[truncated]"
|
||||
return body_str
|
||||
return None
|
||||
|
||||
safe_fields = ("message", "type", "code", "param", "error")
|
||||
|
||||
Reference in New Issue
Block a user