{"record":{"id":"b885ac5e440bb89d","repo":"diegosouzapw/OmniRoute","slug":"request-body-exceeds-formatbytes-limit","errorCode":null,"errorMessage":"Request body exceeds ${formatBytes(limit)}","messagePattern":"Request body exceeds (.+?)","errorType":"validation","errorClass":"RequestBodyTooLargeError","httpStatus":413,"severity":"error","filePath":"src/shared/middleware/bodySizeGuard.ts","lineNumber":141,"sourceCode":"\nexport class RequestBodyTooLargeError extends Error {\n  constructor(readonly limit: number) {\n    super(`Request body exceeds ${formatBytes(limit)}`);\n    this.name = \"RequestBodyTooLargeError\";\n  }\n}\n\n/**\n * Read a request body while enforcing the actual streamed byte count. This closes the gap left by\n * Content-Length-only admission for chunked or deliberately mislabelled requests.\n */\nexport async function readRequestBodyWithLimit(\n  request: Request,\n  limit: number\n): Promise<Uint8Array<ArrayBuffer>> {\n  const declaredLength = Number.parseInt(request.headers.get(\"content-length\") || \"\", 10);\n  if (!Number.isNaN(declaredLength) && declaredLength > limit) {\n    throw new RequestBodyTooLargeError(limit);\n  }\n  if (!request.body) return new Uint8Array(0);\n\n  const reader = request.body.getReader();\n  const chunks: Uint8Array[] = [];\n  let total = 0;\n  try {\n    while (true) {\n      const { done, value } = await reader.read();\n      if (done) break;\n      total += value.byteLength;\n      if (total > limit) {\n        await reader.cancel(\"request body too large\");\n        throw new RequestBodyTooLargeError(limit);\n      }\n      chunks.push(value);\n    }\n  } finally {","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/diegosouzapw/OmniRoute/blob/a179ffed5bb2e0b883b9ae7214ce8717b2a94c4d/src/shared/middleware/bodySizeGuard.ts#L123-L159","documentation":"Error \"Request body exceeds ${formatBytes(limit)}\" thrown in diegosouzapw/OmniRoute.","triggerScenarios":"Thrown at src/shared/middleware/bodySizeGuard.ts:141 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"a179ffed5bb2e0b883b9ae7214ce8717b2a94c4d","analyzedAt":"2026-08-25T18:35:09.898Z","schemaVersion":2},"datasetVersion":"2026-08-25T21:54:21.419Z"}