{"record":{"id":"35a7c639ab86cd9b","repo":"mastra-ai/mastra","slug":"response-body-is-null","errorCode":null,"errorMessage":"Response body is null","messagePattern":"Response body is null","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client-sdks/client-js/src/client.ts","lineNumber":2358,"sourceCode":"   * Opens an SSE stream of background task events (completed/failed).\n   * Returns a Response that can be consumed as a ReadableStream.\n   */\n  public async streamBackgroundTasks(params: StreamBackgroundTasksParams = {}) {\n    const searchParams = new URLSearchParams();\n    if (params.agentId) searchParams.set('agentId', params.agentId);\n    if (params.runId) searchParams.set('runId', params.runId);\n    if (params.threadId) searchParams.set('threadId', params.threadId);\n    if (params.resourceId) searchParams.set('resourceId', params.resourceId);\n    if (params.taskId) searchParams.set('taskId', params.taskId);\n    const qs = searchParams.toString();\n    const response: Response = await this.request(`/background-tasks/stream${qs ? `?${qs}` : ''}`, { stream: true });\n\n    if (!response.ok) {\n      throw new Error(`Failed to stream background tasks: ${response.statusText}`);\n    }\n\n    if (!response.body) {\n      throw new Error('Response body is null');\n    }\n\n    return response.body.pipeThrough(createSseJsonTransform());\n  }\n\n  /**\n   * Lists schedules — agent schedules and workflow schedules — with optional\n   * filtering by agentId, workflowId, or status. Agent schedules can\n   * additionally be filtered by threadId, resourceId, or name.\n   */\n  public listSchedules(params: ListSchedulesParams = {}): Promise<ListSchedulesResponse> {\n    const searchParams = new URLSearchParams();\n    if (params.agentId) searchParams.set('agentId', params.agentId);\n    if (params.workflowId) searchParams.set('workflowId', params.workflowId);\n    if (params.status) searchParams.set('status', params.status);\n    if (params.threadId) searchParams.set('threadId', params.threadId);\n    if (params.resourceId) searchParams.set('resourceId', params.resourceId);\n    if (params.name) searchParams.set('name', params.name);","sourceCodeStart":2340,"sourceCodeEnd":2376,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/client-sdks/client-js/src/client.ts#L2340-L2376","documentation":"After a successful (response.ok) request to /background-tasks/stream, the client checks that a body exists to pipe through the SSE JSON transform. A 2xx response with a null body (possible in some runtimes/polyfills, or with certain proxies that strip bodies) triggers this throw.","triggerScenarios":"The stream request returned ok but response.body is null — typically when running in a non-DOM runtime without streaming support, using a fetch polyfill, or an interceptor/proxy consuming the body.","commonSituations":"Node < 18 or environments lacking native streaming fetch; react-native fetch polyfills; a global fetch mock in tests that returns a Response without a body.","solutions":["Run on a runtime with native streaming fetch support (Node 18+, modern browsers).","Remove or fix fetch polyfills/interceptors that consume or drop the response body.","In tests, mock the response with a real ReadableStream body instead of a bare Response."],"exampleFix":"// before (test mock)\nglobal.fetch = vi.fn().mockResolvedValue(new Response(null, { status: 200 }));\n// after\nglobal.fetch = vi.fn().mockResolvedValue(new Response(new ReadableStream({ start(c) { c.enqueue(encoder.encode('data: {}\\n\\n')); c.close(); } }), { status: 200 }));","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"function hasBody(res: Response): res is Response & { body: ReadableStream<Uint8Array> } {\n  return res.body !== null;\n}","tryCatchPattern":"try {\n  const stream = await client.streamBackgroundTasks(params);\n} catch (e) {\n  if (e instanceof Error && e.message === 'Response body is null') {\n    // runtime lacks streaming fetch; fall back to polling background tasks\n  }\n  throw e;\n}","preventionTips":["Run on Node 18+ or modern browsers with native streaming fetch.","Avoid fetch polyfills/interceptors that consume response bodies.","Fallback to polling the background-tasks list endpoint when streaming is unsupported."],"tags":["streaming","runtime","http"],"backgroundTag":"empty-response-body","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}