diegosouzapw/OmniRoute · error · RequestBodyTooLargeError
Request body exceeds ${formatBytes(limit)}
Error message
Request body exceeds ${formatBytes(limit)} What it means
Error "Request body exceeds ${formatBytes(limit)}" thrown in diegosouzapw/OmniRoute.
Source
Thrown at src/shared/middleware/bodySizeGuard.ts:141
export class RequestBodyTooLargeError extends Error {
constructor(readonly limit: number) {
super(`Request body exceeds ${formatBytes(limit)}`);
this.name = "RequestBodyTooLargeError";
}
}
/**
* Read a request body while enforcing the actual streamed byte count. This closes the gap left by
* Content-Length-only admission for chunked or deliberately mislabelled requests.
*/
export async function readRequestBodyWithLimit(
request: Request,
limit: number
): Promise<Uint8Array<ArrayBuffer>> {
const declaredLength = Number.parseInt(request.headers.get("content-length") || "", 10);
if (!Number.isNaN(declaredLength) && declaredLength > limit) {
throw new RequestBodyTooLargeError(limit);
}
if (!request.body) return new Uint8Array(0);
const reader = request.body.getReader();
const chunks: Uint8Array[] = [];
let total = 0;
try {
while (true) {
const { done, value } = await reader.read();
if (done) break;
total += value.byteLength;
if (total > limit) {
await reader.cancel("request body too large");
throw new RequestBodyTooLargeError(limit);
}
chunks.push(value);
}
} finally {View on GitHub (pinned to a179ffed5b)
When it happens
Trigger: Thrown at src/shared/middleware/bodySizeGuard.ts:141 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of diegosouzapw/OmniRoute@a179ffed5b (2026-08-25).
Data as JSON: /api/errors/b885ac5e440bb89d.
Report an issue: GitHub.