diegosouzapw/OmniRoute · error

BODY_TOO_LARGE

Error message

BODY_TOO_LARGE

What it means

Sentinel error from readJsonBodyWithLimit: the request body streamed past maxBytes, so the reader is cancelled and BODY_TOO_LARGE is thrown; the command-code auth route's handler catches this sentinel and converts it to a 413 response. It protects memory from oversized callback/OAuth payloads.

Solutions

  1. Catch this sentinel specifically and return 413 with a clear message
  2. Keep maxBytes tight for OAuth callback routes
  3. Ensure the reader is cancelled to free the connection
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/app/api/providers/command-code/auth/shared.ts:100 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/bc7b78c6407eb223. Report an issue: GitHub.

Appendix: source

Thrown at src/app/api/providers/command-code/auth/shared.ts:100

    status: 403,
    headers: callbackCorsHeaders(request),
  });
}

export async function readJsonBodyWithLimit(request: Request, maxBytes: number): Promise<unknown> {
  const reader = request.body?.getReader();
  if (!reader) return request.json();

  const chunks: Uint8Array[] = [];
  let total = 0;
  while (true) {
    const { value, done } = await reader.read();
    if (done) break;
    if (!value) continue;
    total += value.byteLength;
    if (total > maxBytes) {
      await reader.cancel();
      throw new Error("BODY_TOO_LARGE");
    }
    chunks.push(value);
  }

  const body = new TextDecoder().decode(Buffer.concat(chunks));
  return JSON.parse(body);
}

export function buildCommandCodeCliCallbackUrl(): string {
  const configuredPort = process.env.COMMAND_CODE_CALLBACK_PORT || "";
  const port = /^\d+$/.test(configuredPort)
    ? Number.parseInt(configuredPort, 10)
    : COMMAND_CODE_CLI_CALLBACK_PORTS[0];
  const safePort = COMMAND_CODE_CLI_CALLBACK_PORTS.includes(
    port as (typeof COMMAND_CODE_CLI_CALLBACK_PORTS)[number]
  )
    ? port
    : COMMAND_CODE_CLI_CALLBACK_PORTS[0];

View on GitHub (pinned to a179ffed5b)