{"record":{"id":"fd24fc5546e03c93","repo":"upstash/context7","slug":"invalid-response","errorCode":"invalid_response","errorMessage":"Request did not return a result","messagePattern":"Request did not return a result","errorType":"error_code","errorClass":"Context7Error","httpStatus":null,"severity":"error","filePath":"packages/sdk/src/commands/command.ts","lineNumber":30,"sourceCode":"  public readonly endpoint: EndpointVariants;\n\n  constructor(request: CommandRequest, endpoint: EndpointVariants) {\n    this.request = request;\n    this.endpoint = endpoint;\n  }\n\n  /**\n   * Execute the command using a client.\n   */\n  public async exec(client: Requester): Promise<TResult> {\n    return this.requestResult<TResult>(client);\n  }\n\n  protected async requestResult<T>(client: Requester): Promise<T> {\n    const { result } = await client.request<T>({ ...this.request, path: [this.endpoint] });\n\n    if (result === undefined) {\n      throw new Context7Error(\"Request did not return a result\", {\n        code: \"invalid_response\",\n      });\n    }\n\n    return result;\n  }\n}\n","sourceCodeStart":12,"sourceCodeEnd":38,"githubUrl":"https://github.com/upstash/context7/blob/4416fb855b8f752be735e34f943b5d0762701aad/packages/sdk/src/commands/command.ts#L12-L38","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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'"],"exampleFix":"// before\nconst libs = await client.searchLibrary('react');\n// after\ntry {\n  const libs = await client.searchLibrary('react');\n} catch (e) {\n  if (e instanceof Context7Error && e.code === 'invalid_response') {\n    // inspect raw payload / retry\n  }\n}","handlingStrategy":"try-catch","validationCode":"null","typeGuard":null,"tryCatchPattern":"try {\n  const result = await command.exec(client);\n} catch (e) {\n  if (e instanceof Context7Error && e.code === 'invalid_response') {\n    // log raw response via onResponse hook, verify baseUrl/API version, optionally retry once\n  } else { throw e; }\n}","preventionTips":["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"],"tags":["api","response","validation","network"],"backgroundTag":"unexpected-response-shape","analyzedSha":"4416fb855b8f752be735e34f943b5d0762701aad","analyzedAt":"2026-09-16T20:28:07.148Z","contentChangedAt":"2026-09-16T20:28:07.148Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}