{"record":{"id":"9eb034e5603bbd75","repo":"honojs/hono","slug":"error-processing-response-error-instanceof-erro","errorCode":null,"errorMessage":"Error processing response: ${error instanceof Error ? error.message : 'Unknown error'}","messagePattern":"Error processing response: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/helper/ssg/ssg.ts","lineNumber":84,"sourceCode":"    filePath = joinPaths(outDir, `${routePath}.${extension}`)\n  }\n\n  ensureWithinOutDir(outDir, filePath)\n\n  return filePath\n}\n\nconst parseResponseContent = async (response: Response): Promise<string | ArrayBuffer> => {\n  const contentType = response.headers.get('Content-Type')\n\n  try {\n    if (contentType?.includes('text') || contentType?.includes('json')) {\n      return await response.text()\n    } else {\n      return await response.arrayBuffer()\n    }\n  } catch (error) {\n    throw new Error(\n      `Error processing response: ${error instanceof Error ? error.message : 'Unknown error'}`\n    )\n  }\n}\n\nexport const defaultExtensionMap: Record<string, string> = {\n  'text/html': 'html',\n  'text/xml': 'xml',\n  'application/xml': 'xml',\n  'application/atom+xml': 'xml',\n  'application/rss+xml': 'xml',\n  'application/yaml': 'yaml',\n}\n\nconst determineExtension = (\n  mimeType: string,\n  userExtensionMap?: Record<string, string>\n): string => {","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/honojs/hono/blob/e2740d5a1bd0b4254e517e3af8b60789284bc7bd/src/helper/ssg/ssg.ts#L66-L102","documentation":"The SSG (Static Site Generation) helper reads the body of each fetched route response to save it to disk. parseResponseContent tries response.text() for text/json content types and response.arrayBuffer() otherwise; if reading the body throws (stream error, aborted fetch, unsupported type), it wraps the underlying failure in this generic Error.","triggerScenarios":"During `toSSG(app, fs, options)` a page handler returns a Response whose stream fails mid-read (upstream fetch died, body already consumed by other code), or arrayBuffer()/text() rejects on a non-cloneable/locked body. The underlying error message is appended.","commonSituations":"SSG pages that fetch remote content and the remote drops the connection at build time; handlers that consume response.body themselves before returning; returning exotic body types (ReadableStream from another runtime) to the SSG crawler; build environment with restricted network.","solutions":["Check the appended underlying message — it names the real failure (network abort, body locked, etc.)","Make page handlers return self-contained/robust Responses: fetch with retries or use resilient upstream calls, and never consume the body before returning it","Return a fresh `new Response(...)` (string/Buffer) from handlers instead of piping remote streams","Verify network access/DNS in the CI/build environment when pages fetch external APIs"],"exampleFix":"// before\napp.get('/page', async (c) => {\n  return fetch('https://api.example.com/data') // stream may fail during SSG read\n})\n\n// after\napp.get('/page', async (c) => {\n  const res = await fetch('https://api.example.com/data')\n  const body = await res.text() // materialize before returning\n  return c.html(render(body))\n}","handlingStrategy":"try-catch","validationCode":"async function safeFetchPage(url: string): Promise<Response | null> {\n  try {\n    const r = await fetch(url)\n    if (!r.ok) return null\n    await r.arrayBuffer() // warm/validate body readability\n    return r.clone()\n  } catch { return null }\n}","typeGuard":null,"tryCatchPattern":"try { await toSSG(app, fs) } catch (e) { if (e instanceof Error && e.message.startsWith('Error processing response:')) { console.error(e.message); process.exit(1) } throw e }","preventionTips":["Materialize remote bodies (await res.text()) in handlers before returning Responses","Never read a Response body in a handler and also return the same Response to SSG","Make upstream fetches in SSG pages retry-capable or cached"],"tags":["ssg","static-generation","response-body","build"],"backgroundTag":"response-body-read-failed","analyzedSha":"e2740d5a1bd0b4254e517e3af8b60789284bc7bd","analyzedAt":"2026-08-28T10:18:08.750Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}