fix: detect and sanitize HTML error pages in agent responses

This commit is contained in:
Kastrah 2026-01-26 11:05:59 +01:00
parent fa4222fdee
commit 6f37fe0acc
2 changed files with 7 additions and 0 deletions

View File

@ -12,6 +12,7 @@ Docs: https://docs.clawd.bot
### Fixes
- Web UI: hide internal `message_id` hints in chat bubbles.
- Heartbeat: normalize target identifiers for consistent routing.
- Agent errors: detect and sanitize HTML error pages from external APIs (prevents Next.js 404 pages being sent to messaging channels).
## 2026.1.23-1

View File

@ -273,6 +273,12 @@ export function formatAssistantErrorText(
return formatRawAssistantErrorForUi(raw);
}
// Detect HTML error pages (e.g., Next.js 404s from misconfigured API endpoints)
if (raw.includes("<!DOCTYPE") || raw.includes("<html") || /<head[\s>]/.test(raw)) {
console.warn("[formatAssistantErrorText] HTML error page received:", raw.slice(0, 200));
return "The AI service returned an unexpected error page. The API endpoint may be misconfigured or temporarily unavailable.";
}
// Never return raw unhandled errors - log for debugging but return safe message
if (raw.length > 600) {
console.warn("[formatAssistantErrorText] Long error truncated:", raw.slice(0, 200));