Skip to content

Commit 59caf03

Browse files
chris-yyausteipete
authored andcommitted
Avoid rescanning HTML challenge pages during error formatting
The HTML challenge fix already keeps standalone CDN block pages out of the DNS transport path. This follow-up caches the HTML classification so status-prefixed non-HTML failures do not pay for the same scan twice and the control flow stays simpler. Constraint: Keep behavior identical for both status-prefixed HTML pages and standalone HTML challenge pages Rejected: Inline the helper into the status branch only | would duplicate the standalone HTML branch logic Confidence: high Scope-risk: narrow Directive: If this formatter grows more branches, keep a single HTML classification result and reuse it through the decision tree Tested: oxfmt --check src/shared/assistant-error-format.ts Tested: node scripts/test-projects.mjs src/agents/pi-embedded-helpers.formatassistanterrortext.test.ts src/agents/pi-embedded-helpers.isbillingerrormessage.test.ts
1 parent 36dd58a commit 59caf03

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

src/shared/assistant-error-format.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,12 @@ export function formatRawAssistantErrorForUi(raw?: string): string {
182182
}
183183

184184
const leadingStatus = extractLeadingHttpStatus(trimmed);
185-
if (leadingStatus && isCloudflareOrHtmlErrorPage(trimmed)) {
185+
const isHtmlChallenge = isCloudflareOrHtmlErrorPage(trimmed);
186+
if (leadingStatus && isHtmlChallenge) {
186187
return `The AI service is temporarily unavailable (HTTP ${leadingStatus.code}). Please try again in a moment.`;
187188
}
188189

189-
if (isCloudflareOrHtmlErrorPage(trimmed)) {
190+
if (isHtmlChallenge) {
190191
return (
191192
"The provider returned an HTML error page instead of an API response. " +
192193
"This usually means a CDN or gateway (e.g. Cloudflare) blocked the request. " +

0 commit comments

Comments
 (0)