{"record":{"id":"e3729d4e3ac44f1b","repo":"Hmbown/CodeWhale","slug":"cause-message","errorCode":null,"errorMessage":"${cause.message}","messagePattern":"\\$\\{cause\\.message\\}","errorType":"http","errorClass":"FormBodyError","httpStatus":null,"severity":"error","filePath":"web/lib/bounded-form.ts","lineNumber":26,"sourceCode":"    super(message);\n    this.name = \"FormBodyError\";\n  }\n}\n\nexport async function readBoundedUrlEncodedForm(\n  request: Request,\n  maxBytes: number\n): Promise<URLSearchParams> {\n  const mediaType = request.headers.get(\"content-type\")?.split(\";\", 1)[0]?.trim().toLowerCase();\n  if (mediaType !== \"application/x-www-form-urlencoded\") {\n    throw new FormBodyError(415, \"expected application/x-www-form-urlencoded\");\n  }\n\n  try {\n    const bytes = await readBoundedBody(request, maxBytes);\n    return new URLSearchParams(new TextDecoder().decode(bytes));\n  } catch (cause) {\n    if (cause instanceof BodyReadError) throw new FormBodyError(cause.status, cause.message);\n    throw cause;\n  }\n}\n","sourceCodeStart":8,"sourceCodeEnd":30,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/web/lib/bounded-form.ts#L8-L30","documentation":"readBoundedUrlEncodedForm wraps BodyReadError thrown by readBoundedBody into FormBodyError, reusing its HTTP status and message (hence the dynamic \"${cause.message}\"). Non-BodyReadError causes are rethrown unchanged.","triggerScenarios":"The form body read failed inside readBoundedBody: invalid Content-Length (400), payload too large (413), or a body read failure (400) — then surfaced to the caller as FormBodyError with that message.","commonSituations":"Oversized form posts to admin routes; malformed Content-Length from custom clients; aborted/failed streams. The visible message is the underlying cause, so fix that cause.","solutions":["Read cause.message to identify the underlying failure (invalid Content-Length vs payload too large vs read failure).","If the message is \"payload too large\", shrink the body or raise the maxBytes limit at the call site.","If the message is \"invalid Content-Length\", fix the client's header; for \"body read failed\", retry the request."],"exampleFix":"// before\nconst res = await fetch(url, { method: \"POST\", body: hugeBody });\n// after\nif (new TextEncoder().encode(bodyString).byteLength > MAX_BYTES) throw new Error(\"body exceeds limit\");\nconst res = await fetch(url, { method: \"POST\", body: bodyString });","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const form = await readBoundedUrlEncodedForm(request, MAX);\n} catch (err) {\n  if (err instanceof FormBodyError) {\n    return new Response(err.message, { status: err.status });\n  }\n  throw err; // non-body errors propagate unchanged\n}","preventionTips":["Fix the underlying cause named in err.message (size, content-length, or read failure) rather than retrying blindly.","Enforce the same body-size limit client-side to avoid 413s from this wrapper.","Log FormBodyError status + message server-side to spot abusive clients early."],"tags":["http","error-handling","payload-size"],"backgroundTag":"http-error-response","analyzedSha":"433685b2024e7bc4c99e1e2e326bcad39b4d9d65","analyzedAt":"2026-09-15T12:24:24.634Z","contentChangedAt":"2026-09-15T12:24:24.634Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}