{"record":{"id":"27aacbcde1969db9","repo":"JuliusBrussee/caveman","slug":"await-response-text","errorCode":null,"errorMessage":"await response.text()","messagePattern":"await response\\.text\\(\\)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/sdk/typescript/src/index.ts","lineNumber":2103,"sourceCode":"  if (target.origin !== base.origin || (target.pathname !== prefix && !target.pathname.startsWith(`${prefix}/`))) {\n    throw new Error(\"cave_provider_raw_path_not_allowed\");\n  }\n  const merged = new Headers(request.headers);\n  const gatewayHeaders = headers(cave, cave.options.defaultWorkflow ?? \"unlabeled-workflow\", upstreamKey);\n  for (const [name, value] of Object.entries(gatewayHeaders)) {\n    if (name !== \"content-type\") merged.set(name, value);\n  }\n  return caveFetch(cave, new Request(request, { headers: merged }));\n}\n\nasync function providerFetch(cave: Cave, path: string, body: unknown, workflow: string, hint?: Record<string, unknown>, upstreamKey?: string, trace?: TraceContext) {\n  const assemblyHeader = body !== null && typeof body === \"object\" ? assemblyRequestHeaders.get(body as object) : undefined;\n  const response = await caveFetch(cave, `${cave.options.baseURL}${path}`, {\n    method: \"POST\",\n    headers: headers(cave, workflow, upstreamKey, assemblyHeader ? { ...hint, assemblyHeader } : hint, trace),\n    body: JSON.stringify(body)\n  });\n  if (!response.ok) throw new Error(await response.text());\n  return response.json();\n}\n\nexport class CaveRequestError extends Error {\n  constructor(readonly status: number, readonly path: string, message: string) {\n    super(message);\n    this.name = \"CaveRequestError\";\n  }\n}\n\nasync function request(cave: Cave, path: string, body?: unknown, workflow?: string, trace?: TraceContext, extraHeaders?: Record<string, string>): Promise<Record<string, unknown>> {\n  const init: RequestInit = {\n    method: body === undefined ? \"GET\" : \"POST\",\n    headers: { ...headers(cave, workflow ?? cave.options.defaultWorkflow ?? \"unlabeled-workflow\", undefined, undefined, trace), ...extraHeaders }\n  };\n  if (body !== undefined) init.body = JSON.stringify(body);\n  const response = await caveFetch(cave, `${cave.options.baseURL}${path}`, init);\n  if (!response.ok) {","sourceCodeStart":2085,"sourceCodeEnd":2121,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/sdk/typescript/src/index.ts#L2085-L2121","documentation":"Error body from providerFetch when reading the gateway response with await response.text() fails or the read yields an unusable body: the fetch itself completed but the payload could not be read/decoded to surface a provider error, so the raw read expression surfaces as the message.","triggerScenarios":"Thrown at packages/sdk/typescript/src/index.ts:2103 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Retry the provider call: body-read failures are usually transient truncation or a dropped connection","Check network/proxy stability between the SDK and the gateway","If reproducible, capture response headers/status and inspect gateway logs for a malformed response"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}