Files
openclaw/src/shared/http-error-response.ts
T
Pengyi Peng a816c4a3b4 fix(errors): detect HTML after HTTP reason phrases
Share one internal HTTP response-body parser across assistant error formatting and provider runtime failure classification so reason phrases do not hide complete HTML error pages.

Fixes #122244.
2026-08-14 00:01:14 +01:00

18 lines
522 B
TypeScript

const HTML_ERROR_PREFIX_RE = /^\s*(?:<!doctype\s+html\b|<html\b)/i;
export function extractHttpResponseBody(
status: { code: number; rest: string } | null,
): { code: number; body: string } | null {
if (!status) {
return null;
}
if (HTML_ERROR_PREFIX_RE.test(status.rest)) {
return { code: status.code, body: status.rest };
}
const lineBreak = status.rest.indexOf("\n");
return {
code: status.code,
body: lineBreak === -1 ? status.rest : status.rest.slice(lineBreak + 1).trimStart(),
};
}