diegosouzapw/OmniRoute · error

Invalid JSON edit body

Error message

Invalid JSON edit body: ${err instanceof Error ? err.message : err}

What it means

images/edits JSON parse/transform failure: JSON.parse or extraction of the edit input from the parsed JSON threw — structurally broken JSON or an unexpected value type during extractImageEditInputFromJson. Logged and mapped to a 400.

Solutions

  1. Validate the JSON syntax before sending
  2. Check data-URL image fields are properly formatted strings
  3. Send multipart/form-data for binary inputs
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at src/app/api/v1/images/edits/route.ts:181 when the library encounters an invalid state.

Common situations: See trigger scenarios.

Understand the failure class


AI-assisted analysis of diegosouzapw/OmniRoute@a179ffed5b (2026-08-25). Data as JSON: /api/errors/9d51e673faccd9c5. Report an issue: GitHub.

Appendix: source

Thrown at src/app/api/v1/images/edits/route.ts:181

      }).formData();
      return await readMultipartImage(formData);
    } catch (err) {
      log.warn("IMAGE", `Invalid multipart body: ${err instanceof Error ? err.message : err}`);
      return null;
    }
  }
  if (contentType.includes("application/json")) {
    try {
      const parsed = ImageEditJsonSchema.safeParse(
        JSON.parse(new TextDecoder().decode(rawBody)) as unknown
      );
      if (!parsed.success) {
        log.warn("IMAGE", `Invalid JSON edit body shape: ${parsed.error.message}`);
        return null;
      }
      return extractImageEditInputFromJson(parsed.data);
    } catch (err) {
      log.warn("IMAGE", `Invalid JSON edit body: ${err instanceof Error ? err.message : err}`);
      return null;
    }
  }
  return null;
}

function jsonResponse(data: unknown, status = 200): Response {
  return new Response(JSON.stringify(data), {
    status,
    headers: { "Content-Type": "application/json" },
  });
}

/** Reduce reference images (multi + single fallback) to data-URL strings for Firefly. */
function buildAdobeFireflyEditDataUrls(
  images: Array<{ bytes: Buffer; mime: string }>,
  imageBytes: Buffer | null,
  imageMime: string | null

View on GitHub (pinned to a179ffed5b)