{"record":{"id":"3b6983a6267c3e28","repo":"vercel/ai","slug":"failed-to-fetch-the-response","errorCode":null,"errorMessage":"Failed to fetch the response.","messagePattern":"Failed to fetch the response\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/angular/src/lib/structured-object.ng.ts","lineNumber":161,"sourceCode":"      this.#error.set(undefined);\n\n      const abortController = new AbortController();\n      this.#abortController = abortController;\n\n      const actualFetch = this.options.fetch ?? fetch;\n      const response = await actualFetch(this.options.api, {\n        method: 'POST',\n        headers: {\n          'Content-Type': 'application/json',\n          ...normalizeHeaders(this.options.headers),\n        },\n        credentials: this.options.credentials,\n        signal: abortController.signal,\n        body: JSON.stringify(input),\n      });\n\n      if (!response.ok) {\n        throw new Error(\n          (await response.text()) ?? 'Failed to fetch the response.',\n        );\n      }\n\n      if (response.body == null) {\n        throw new Error('The response body is empty.');\n      }\n\n      let accumulatedText = '';\n      let latestObject: DeepPartial<RESULT> | undefined = undefined;\n\n      await response.body.pipeThrough(new TextDecoderStream()).pipeTo(\n        new WritableStream<string>({\n          write: async chunk => {\n            if (abortController?.signal.aborted) {\n              throw new DOMException('Stream aborted', 'AbortError');\n            }\n            accumulatedText += chunk;","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/angular/src/lib/structured-object.ng.ts#L143-L179","documentation":"The Angular `StructuredObject` helper issues a fetch to its backing endpoint and throws this generic message when the HTTP response is not ok and the error body text is empty. It signals the server rejected the request but provided no readable error payload.","triggerScenarios":"A `fetch` inside StructuredObject's stream loop returns `response.ok === false` and `await response.text()` resolves to an empty/falsy string, so the fallback message is thrown.","commonSituations":"Server returning 500 with an empty body, proxy/gateway stripping error bodies (502/504), CORS-blocked responses surfacing as opaque failures, wrong endpoint URL in `options.api`.","solutions":["Inspect the network tab for the actual status code and response of the failing request.","Fix the server/proxy so it returns a JSON error body; the code surfaces the body text when present.","Verify `options.api`/`credentials`/headers point to the correct structured-object endpoint.","Ensure CORS headers allow the request so the body is readable from the browser."],"exampleFix":"// server: return a readable error instead of an empty 500\n// before\nres.statusCode = 500; res.end();\n// after\nres.statusCode = 500; res.setHeader('content-type','application/json');\nres.end(JSON.stringify({ error: { message: 'Model unavailable' } }));","handlingStrategy":"try-catch","validationCode":"const res = await fetch(url, { method: 'HEAD' });\nif (!res.ok) throw new Error(`Endpoint unhealthy: ${res.status}`);","typeGuard":"function isOkResponse(r: Response): r is Response & { ok: true } { return r.ok; }","tryCatchPattern":"try {\n  const obj = experimental_useStructuredObject({ api: '/api/object', schema });\n} catch (e) {\n  if (e instanceof Error && e.message === 'Failed to fetch the response.') {\n    // check server response/status and CORS\n  }\n  throw e;\n}","preventionTips":["Return a JSON error body from your endpoint on failure so real messages surface.","Keep the structured-object API route and credentials correct.","Verify CORS allows the browser to read error bodies.","Monitor server logs for 5xx on the object endpoint."],"tags":["network","fetch","http","angular"],"backgroundTag":"http-request-failed","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}