diegosouzapw/OmniRoute · error
PAYLOAD_TOO_LARGE
PAYLOAD_TOO_LARGE
Error message
Request body too large. Maximum allowed: ${formatBytes(limit)} What it means
bodySizeGuard 413: the request's Content-Length exceeds the per-route body size limit (custom route rule or the global configured max). The guard short-circuits before the body is read, refusing oversized uploads.
Solutions
- Reduce payload size below the stated limit
- Raise the route's limit in body-size settings
- Stream large inputs or reference them by URL instead of inlining
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at src/shared/middleware/bodySizeGuard.ts:108 when the library encounters an invalid state.
Common situations: See trigger scenarios.
Understand the failure class
Background: payload too large / request exceeds maximum size: why libraries cap bytes and how to fix oversize payloads — this error's family across 50 libraries.
AI-assisted analysis of diegosouzapw/OmniRoute@a179ffed5b (2026-08-25).
Data as JSON: /api/errors/334ea058d49c00c8.
Report an issue: GitHub.
Appendix: source
Thrown at src/shared/middleware/bodySizeGuard.ts:108
return customRule.fixedLimit ? customRule.limit : Math.max(customRule.limit, configuredLimit);
}
/**
* Check Content-Length header against the configured limit.
* Returns a 413 Response if the body is too large, or null if OK.
*/
export function checkBodySize(request: Request, limit: number = MAX_BODY_BYTES): Response | null {
const contentLength = request.headers.get("content-length");
if (contentLength) {
const bytes = Number.parseInt(contentLength, 10);
if (!Number.isNaN(bytes) && bytes > limit) {
return new Response(
JSON.stringify({
error: {
message: `Request body too large. Maximum allowed: ${formatBytes(limit)}`,
type: "payload_too_large",
code: "PAYLOAD_TOO_LARGE",
},
}),
{
status: 413,
headers: {
"Content-Type": "application/json",
},
}
);
}
}
return null;
}
export class RequestBodyTooLargeError extends Error {
constructor(readonly limit: number) {
super(`Request body exceeds ${formatBytes(limit)}`);View on GitHub (pinned to a179ffed5b)