{"version":49,"agent":"pinch","message":"Errors: say an HTML error page by its title and Ray ID\n\nWhen the server fails before it can answer, its host sends an HTML error page instead. The client printed the page's first 300 characters, which are all doctype and IE comments, so nobody could tell what had failed: \"GET /a/me/status answered 500: <!DOCTYPE html> <!--[if lt IE 7]> ...\".\n\nNow an HTML answer reads: answered 500: an HTML error page titled \"Worker threw exception | ... | Cloudflare\" (Ray ID ...), not the server's own answer: the server failed before it could say why. The title and Ray ID are what an operator needs to find the failure. JSON answers and plain text are said as before. Tested in error-sentence.test.ts.","time":1791580366631,"timeIso":"2026-10-09T21:12:46.631Z","changes":2,"change":588,"files":["client/src/api-error.ts","client/test/error-sentence.test.ts"],"draft":null,"diff":[{"path":"client/src/api-error.ts","added":14,"removed":1,"diff":"--- a/client/src/api-error.ts\n+++ b/client/src/api-error.ts\n@@ -36,7 +36,10 @@\n \t);\n }\n \n-/** The server's `{error: \"sentence\"}` answer, or the start of whatever it sent. */\n+/**\n+ * The server's `{error: \"sentence\"}` answer, or the start of whatever it sent. An HTML page (the host's error\n+ * page, when the server itself failed) is said by its title and Ray ID, which its first lines never reach.\n+ */\n export function errorSentence(body: string): string {\n \ttry {\n \t\tconst parsed = JSON.parse(body) as { error?: unknown; reason?: unknown };\n@@ -45,5 +48,15 @@\n \t} catch {\n \t\t// Not JSON.\n \t}\n+\tif (/^\\s*<(!doctype html|html)/i.test(body)) {\n+\t\tconst plain = (s: string) =>\n+\t\t\ts\n+\t\t\t\t.replace(/<[^>]*>/g, \" \")\n+\t\t\t\t.replace(/\\s+/g, \" \")\n+\t\t\t\t.trim();\n+\t\tconst title = plain(/<title>([\\s\\S]*?)<\\/title>/i.exec(body)?.[1] ?? \"\");\n+\t\tconst ray = /Ray ID:\\s*(?:<[^>]*>\\s*)*([0-9a-f]+)/i.exec(body)?.[1];\n+\t\treturn `an HTML error page${title !== \"\" ? ` titled ${JSON.stringify(title)}` : \"\"}${ray ? ` (Ray ID ${ray})` : \"\"}, not the server's own answer: the server failed before it could say why`;\n+\t}\n \treturn body.slice(0, 300);\n }"},{"path":"client/test/error-sentence.test.ts","added":30,"removed":0,"diff":"--- /dev/null\n+++ b/client/test/error-sentence.test.ts\n@@ -0,0 +1,30 @@\n+// errorSentence: what an error answer says, from JSON or from the host's HTML error page.\n+\n+import assert from \"node:assert/strict\";\n+import { test } from \"node:test\";\n+import { errorSentence } from \"../src/api-error.ts\";\n+\n+test(\"a JSON answer gives its error, else its reason\", () => {\n+\tassert.equal(errorSentence('{\"error\":\"no such draft\"}'), \"no such draft\");\n+\tassert.equal(errorSentence('{\"reason\":\"paused\"}'), \"paused\");\n+\tassert.equal(errorSentence(\"plain words\"), \"plain words\");\n+});\n+\n+test(\"an HTML error page is said by its title and Ray ID, not its first lines\", () => {\n+\tconst page = `<!DOCTYPE html>\n+<!--[if lt IE 7]> <html class=\"no-js ie6 oldie\" lang=\"en-US\"> <![endif]-->\n+<head>\n+<title>Worker threw exception | example.workers.dev | Cloudflare</title>\n+</head>\n+<body>${\"<div></div>\\n\".repeat(50)}\n+<span>Cloudflare Ray ID: <strong class=\"font-semibold\">8c1f2e3d4a5b6c7d</strong></span>\n+</body></html>`;\n+\tassert.equal(\n+\t\terrorSentence(page),\n+\t\t'an HTML error page titled \"Worker threw exception | example.workers.dev | Cloudflare\" (Ray ID 8c1f2e3d4a5b6c7d), not the server\\'s own answer: the server failed before it could say why',\n+\t);\n+\tassert.equal(\n+\t\terrorSentence(\"<html><body>oops</body></html>\"),\n+\t\t\"an HTML error page, not the server's own answer: the server failed before it could say why\",\n+\t);\n+});"}],"ci":null}