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
- Log the raw response (client onResponse hook or network tab) to inspect what the server actually returned
- Verify the client baseUrl points at the correct current API host
- Check for API version/SDK mismatch and update the SDK to the latest version
- 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
- Attach an onResponse hook during development to capture unexpected raw payloads
- Pin the SDK and API versions together; update the SDK when the API changes
- Check baseUrl correctness — gateways/wrong hosts often return non-standard bodies
- Handle invalid_response explicitly rather than letting it bubble as a generic 500
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
- Failed to fetch user info
- HTTP from /api/auth/mcp
- Please try again
- query and libraryName are required
- Authentication discovery was redirected. Pass the final…
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)