PaddlePaddle/PaddleOCR · error · ResponseFormatError

Response body is missing data.

Error message

Response body is missing data.

What it means

ResponseFormatError with 'Response body is missing data.' is thrown by fetchJson<T>() when the JSON envelope parsed fine and code was 0/absent, but the top-level `data` field is missing. The SDK's contract requires every successful response to be shaped { code, msg, data }, and it returns payload.data to callers — no data means the contract is broken.

Source

Thrown at api_sdk/typescript/src/internal/http.ts:173

  private async fetchJson<T>(
    url: string,
    init: RequestInit,
    signal?: AbortSignal,
    withAuth: boolean = true,
    timeoutMs?: number,
  ): Promise<T> {
    const resp = await this.fetch(url, init, signal, withAuth, timeoutMs);
    let payload: APIResponse<T>;
    try {
      payload = await resp.json() as APIResponse<T>;
    } catch (error) {
      throw new ResponseFormatError("Expected a JSON response body.", { cause: error });
    }
    if (payload.code !== undefined && payload.code !== 0) {
      throw new APIError(resp.status, payload.msg || "PaddleOCR official API request failed.");
    }
    if (!payload || typeof payload !== "object" || !("data" in payload)) {
      throw new ResponseFormatError("Response body is missing data.");
    }
    return payload.data;
  }

  private async fetch(
    url: string,
    init: RequestInit,
    signal?: AbortSignal,
    withAuth: boolean = true,
    timeoutMs?: number,
  ): Promise<Response> {
    const headers: Record<string, string> = {
      ...(init.headers as Record<string, string> || {}),
    };
    if (withAuth) {
      headers.Authorization = `Bearer ${this.token}`;
      if (this.clientPlatform) {
        headers["Client-Platform"] = this.clientPlatform;

View on GitHub (pinned to 2661c7c0ef)

Solutions

  1. Confirm the base URL targets the real PaddleOCR API host expected by this SDK version
  2. Capture the raw response with a custom fetchImpl to see exactly which field is missing
  3. Align SDK and server versions — the data envelope is part of the contract; drift on either side produces this
  4. If you run a mock server, make it return the full { code: 0, msg: "ok", data: {...} } shape

Example fix

import { ResponseFormatError } from "paddleocr-api/errors";
try {
  const jobs = await client.getBatchStatus(batchId);
} catch (e) {
  if (e instanceof ResponseFormatError && e.message.includes("missing data")) {
    console.error("Server broke the response contract:", e.message);
  }
}
Defensive patterns

Strategy: try-catch

Validate before calling

function hasDataField(v: unknown): v is { data: unknown } {
  return typeof v === "object" && v !== null && "data" in v;
}

Type guard

function isApiResponse<T>(v: unknown): v is { code?: number; msg?: string; data: T } {
  return typeof v === "object" && v !== null && "data" in v;
}

Try / catch

try {
  const jobs = await poller.getBatchStatus(batchId);
} catch (e) {
  if (e instanceof ResponseFormatError && e.message.includes("missing data")) {
    // contract violation: do not retry blindly; verify endpoint and versions
    logger.error("Response contract broken (no data field)");
  }
  throw e;
}

Prevention

When it happens

Trigger: Any JSON API call (submitJson, getJobStatus, getBatchStatus) whose 2xx response body is valid JSON but lacks the data key — e.g. { "code": 0, "msg": "ok" } or a completely unrelated JSON object returned by a misrouted endpoint.

Common situations: Pointing the SDK at a stub/mock server that returns simplified JSON without the data envelope; API version mismatch where a newer/older server drops the envelope; load balancer health-check responses; authentication middlewares that short-circuit with { "msg": ... } JSON.

Related errors


AI-assisted analysis of PaddlePaddle/PaddleOCR@2661c7c0ef (2026-08-14). Data as JSON: /api/errors/b784de12ef692aac. Report an issue: GitHub.