{"record":{"id":"bfd927747786ed5d","repo":"diegosouzapw/OmniRoute","slug":"invalid-json-body-bfd927","errorCode":null,"errorMessage":"Invalid JSON body","messagePattern":"Invalid JSON body","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/app/api/v1/images/generations/route.ts","lineNumber":105,"sourceCode":"// would silently drop entries if a wider helper were reused for headers\n// that can legitimately repeat (e.g., set-cookie).\nconst PUBLIC_BASE_URL_HEADER_KEYS = [\"host\", \"x-forwarded-host\", \"x-forwarded-proto\"] as const;\n\nfunction publicBaseUrlHeaders(headers: Headers): Record<string, string> {\n  const out: Record<string, string> = {};\n  for (const key of PUBLIC_BASE_URL_HEADER_KEYS) {\n    const value = headers.get(key);\n    if (value !== null) out[key] = value;\n  }\n  return out;\n}\n\nasync function postHandler(request, context) {\n  let rawBody;\n  try {\n    rawBody = await request.json();\n  } catch {\n    log.warn(\"IMAGE\", \"Invalid JSON body\");\n    return errorResponse(HTTP_STATUS.BAD_REQUEST, \"Invalid JSON body\");\n  }\n\n  const validation = validateBody(v1ImageGenerationSchema, rawBody);\n  if (isValidationFailure(validation)) {\n    return errorResponse(HTTP_STATUS.BAD_REQUEST, validation.error.message);\n  }\n  const body = validation.data;\n  const startTime = Date.now();\n\n  // Authenticate before policy enforcement. Policy checks intentionally allow\n  // keyless local mode and assume the route has already rejected invalid keys.\n  const authRejection = await enforceClientApiRouteAuth(request);\n  if (authRejection) return authRejection;\n\n  // Enforce API key policies (model restrictions + budget limits)\n  const policy = await enforceApiKeyPolicy(request, body.model);\n  if (policy.rejection) return policy.rejection;","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/diegosouzapw/OmniRoute/blob/a179ffed5bb2e0b883b9ae7214ce8717b2a94c4d/src/app/api/v1/images/generations/route.ts#L87-L123","documentation":"Error \"Invalid JSON body\" thrown in diegosouzapw/OmniRoute.","triggerScenarios":"Thrown at src/app/api/v1/images/generations/route.ts:105 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"}