upstash/context7 · error · Context7Error

invalid_response

invalid_response

Error message

Request did not return a result

What it means

requestResult unwraps the `result` field from the API response envelope for every command. When the server responds without a result (undefined), the SDK treats it as a malformed response and throws Context7Error with code invalid_response rather than returning undefined. This guards callers against silently getting undefined from unexpected payloads.

Solutions

  1. Log the raw response (client onResponse hook or network tab) to inspect what the server actually returned
  2. Verify the client baseUrl points at the correct current API host
  3. Check for API version/SDK mismatch and update the SDK to the latest version
  4. Retry if a transient gateway produced the empty envelope; add error handling for code === 'invalid_response'

Example fix

// before
const libs = await client.searchLibrary('react');
// after
try {
  const libs = await client.searchLibrary('react');
} catch (e) {
  if (e instanceof Context7Error && e.code === 'invalid_response') {
    // inspect raw payload / retry
  }
}
Defensive patterns

Strategy: try-catch

Validate before calling

null

Try / catch

try {
  const result = await command.exec(client);
} catch (e) {
  if (e instanceof Context7Error && e.code === 'invalid_response') {
    // log raw response via onResponse hook, verify baseUrl/API version, optionally retry once
  } else { throw e; }
}

Prevention

When it happens

Trigger: The API response body has no `result` key or it is explicitly undefined — e.g. an error-shaped envelope, an empty 204-style response, a proxy/gateway returning HTML or minimal JSON, or an API version mismatch changing the response shape.

Common situations: Corporate proxies or auth gateways intercepting requests; hitting a deprecated endpoint whose schema changed; rate-limit or maintenance pages returning non-standard bodies; pointing the client at a wrong baseUrl that serves something other than the Context7 API.

Related errors


AI-assisted analysis of upstash/context7@4416fb855b (2026-09-16). Data as JSON: /api/errors/fd24fc5546e03c93. Report an issue: GitHub.

Appendix: source

Thrown at packages/sdk/src/commands/command.ts:30

  public readonly endpoint: EndpointVariants;

  constructor(request: CommandRequest, endpoint: EndpointVariants) {
    this.request = request;
    this.endpoint = endpoint;
  }

  /**
   * Execute the command using a client.
   */
  public async exec(client: Requester): Promise<TResult> {
    return this.requestResult<TResult>(client);
  }

  protected async requestResult<T>(client: Requester): Promise<T> {
    const { result } = await client.request<T>({ ...this.request, path: [this.endpoint] });

    if (result === undefined) {
      throw new Context7Error("Request did not return a result", {
        code: "invalid_response",
      });
    }

    return result;
  }
}

View on GitHub (pinned to 4416fb855b)