paperclipai/paperclip · error · Error

API error ${response.status}: ${message}

Error message

API error ${response.status}: ${message}

What it means

parseFetchResponse throws when response.ok is false. It prefers a server-provided parsed.error string; otherwise it falls back to a status-code message. This is the generic HTTP-error path for issue command fetches.

Source

Thrown at cli/src/commands/client/issue.ts:1439

): Promise<Buffer> {
  const response = await fetch(buildApiUrl(apiBase, apiPath`/api/attachments/${attachmentId}/content`), {
    headers: apiKey ? { authorization: `Bearer ${apiKey}` } : undefined,
  });
  if (!response.ok) {
    await parseFetchResponse(response);
  }
  return Buffer.from(await response.arrayBuffer());
}

async function parseFetchResponse(response: Response): Promise<unknown> {
  const text = await response.text();
  const parsed = text.trim() ? safeJson(text) : null;
  if (!response.ok) {
    const message =
      typeof parsed === "object" && parsed !== null && "error" in parsed && typeof parsed.error === "string"
        ? parsed.error
        : `Request failed with status ${response.status}`;
    throw new Error(`API error ${response.status}: ${message}`);
  }
  return parsed;
}

function safeJson(text: string): unknown {
  try {
    return JSON.parse(text) as unknown;
  } catch {
    return text;
  }
}

View on GitHub (pinned to 67001ec6eb)

Solutions

  1. Inspect err.message: the leading number is the status code, the rest is the server message.
  2. For 401/403, refresh or re-scope the API key.
  3. For 404, verify the issue id and company scope.
  4. For 5xx, check API health and retry.
Defensive patterns

Strategy: try-catch

Try / catch

try {
  const data = await parseFetchResponse(response);
} catch (err) {
  const msg = err instanceof Error ? err.message : String(err);
  const status = Number(/^(\d{3})/.exec(msg)?.[1]);
  if (status === 401) await refreshAuthToken();
  if (status >= 500) {/* retry with backoff */}
  throw err;
}

Prevention

When it happens

Trigger: Any non-2xx response from an issue endpoint: 400 bad request, 401 unauthorized, 403 forbidden, 404 not found, 409 conflict, 422 validation, 500 server error.

Common situations: Expired/invalid API key (401); wrong issue id (404); validation failure (422); server outage (5xx); rate limiting.

Related errors


AI-assisted analysis of paperclipai/paperclip@67001ec6eb (2026-08-12). Data as JSON: /api/errors/5c9140a226c3cdbd. Report an issue: GitHub.