{"record":{"id":"c37db846eb204fcf","repo":"vercel/ai","slug":"failed-to-fetch-the-response-c37db8","errorCode":null,"errorMessage":"Failed to fetch the response.","messagePattern":"Failed to fetch the response\\.","errorType":"http","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/svelte/src/structured-object.svelte.ts","lineNumber":172,"sourceCode":"      this.#store.loading = true;\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          ...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":154,"sourceCodeEnd":190,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/svelte/src/structured-object.svelte.ts#L154-L190","documentation":"In the Svelte useStructuredObject internals, when the fetch response is not OK the code throws the response body text as the error; the generic message 'Failed to fetch the response.' is the fallback when the body text is empty. It means the server rejected the streaming/structured-generation request (any non-2xx status).","triggerScenarios":"Calling useStructuredObject / the internal fetch when the API endpoint returns 4xx/5xx (bad API key, invalid schema input, server error) and the response body text is empty or null.","commonSituations":"Proxy/serverless endpoint returning an error without a body; wrong API route path; auth middleware rejecting the request; rate limiting with empty body.","solutions":["Inspect the HTTP status and your API endpoint's logs for the real cause.","Ensure the api key/auth headers are sent with the request.","Return a JSON error body from your endpoint so the message is informative.","Verify the endpoint URL/credentials option points to your structured-output handler."],"exampleFix":"// before (server route, empty error body)\nreturn new Response(null, { status: 500 });\n// after\nreturn new Response(JSON.stringify({ error: 'Model overloaded' }), { status: 500 });","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"const { error } = useStructuredObject(...);\n// effect:\nif (error) {\n  const msg = error instanceof Error ? error.message : String(error);\n  console.error('structured object request failed:', msg);\n}","preventionTips":["Verify the endpoint URL and API key before calls.","Have the server return informative JSON error bodies.","Check server logs for 4xx/5xx responses.","Add auth headers/credentials to the fetch options."],"tags":["http","fetch","svelte","streaming"],"backgroundTag":"http-request-failed","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}