{"record":{"id":"5c9140a226c3cdbd","repo":"paperclipai/paperclip","slug":"api-error-response-status-message","errorCode":null,"errorMessage":"API error ${response.status}: ${message}","messagePattern":"API error (.+?): (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"cli/src/commands/client/issue.ts","lineNumber":1445,"sourceCode":"): Promise<Buffer> {\n  const response = await fetch(buildApiUrl(apiBase, apiPath`/api/attachments/${attachmentId}/content`), {\n    headers: apiKey ? { authorization: `Bearer ${apiKey}` } : undefined,\n  });\n  if (!response.ok) {\n    await parseFetchResponse(response);\n  }\n  return Buffer.from(await response.arrayBuffer());\n}\n\nasync function parseFetchResponse(response: Response): Promise<unknown> {\n  const text = await response.text();\n  const parsed = text.trim() ? safeJson(text) : null;\n  if (!response.ok) {\n    const message =\n      typeof parsed === \"object\" && parsed !== null && \"error\" in parsed && typeof parsed.error === \"string\"\n        ? parsed.error\n        : `Request failed with status ${response.status}`;\n    throw new Error(`API error ${response.status}: ${message}`);\n  }\n  return parsed;\n}\n\nfunction safeJson(text: string): unknown {\n  try {\n    return JSON.parse(text) as unknown;\n  } catch {\n    return text;\n  }\n}\n","sourceCodeStart":1427,"sourceCodeEnd":1457,"githubUrl":"https://github.com/paperclipai/paperclip/blob/3f1d897a7c018d76563a21c6e39c3c9b03933622/cli/src/commands/client/issue.ts#L1427-L1457","documentation":"parseFetchResponse re-throws a non-OK attachment download response, extracting the server's JSON error message if present; the guard fires for any failed raw fetch to the attachments content endpoint.","triggerScenarios":"Thrown at cli/src/commands/client/issue.ts:1439 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Read the API error message in the output, fix the request (parameters/permissions), and retry."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"3f1d897a7c018d76563a21c6e39c3c9b03933622","analyzedAt":"2026-08-18T22:49:45.177Z","contentChangedAt":"2026-08-18T22:49:45.177Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}