{"record":{"id":"0b2ef33802bcc97a","repo":"rohitg00/agentmemory","slug":"post-url-failed-res-status-res-statustext","errorCode":null,"errorMessage":"POST ${url} failed: ${res.status} ${res.statusText}${suffix}","messagePattern":"POST (.+?) failed: (.+?) (.+?)(.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/cli.ts","lineNumber":2841,"sourceCode":"    return null;\n  }\n}\n\nasync function postJsonStrict<T = unknown>(\n  url: string,\n  body: unknown,\n  timeoutMs = 5000,\n): Promise<T | null> {\n  const res = await fetch(url, {\n    method: \"POST\",\n    headers: { \"Content-Type\": \"application/json\" },\n    body: JSON.stringify(body),\n    signal: AbortSignal.timeout(timeoutMs),\n  });\n  if (!res.ok) {\n    const errBody = await res.text().catch(() => \"\");\n    const suffix = errBody ? ` — ${errBody.slice(0, 200)}` : \"\";\n    throw new Error(`POST ${url} failed: ${res.status} ${res.statusText}${suffix}`);\n  }\n  return (await res.json().catch(() => null)) as T | null;\n}\n\nasync function seedDemoSession(\n  base: string,\n  project: string,\n  session: DemoSession,\n): Promise<number> {\n  await postJsonStrict(`${base}/agentmemory/session/start`, {\n    sessionId: session.id,\n    project,\n    cwd: project,\n  });\n\n  let stored = 0;\n  for (const obs of session.observations) {\n    const url = `${base}/agentmemory/observe`;","sourceCodeStart":2823,"sourceCodeEnd":2859,"githubUrl":"https://github.com/rohitg00/agentmemory/blob/e04ba88819c365c9acf9d6661ea802143e728bd6/src/cli.ts#L2823-L2859","documentation":"This error is thrown by the CLI's internal HTTP POST helper when the iii-engine/agentmemory daemon responds with a non-2xx status. The message includes the URL, HTTP status code, status text, and up to 200 chars of the response body to help diagnose the server-side failure. It wraps any failed POST the CLI makes (session seed, events, etc.).","triggerScenarios":"Any CLI command that POSTs to the REST API where the daemon returns 4xx/5xx: wrong port/URL, daemon not running (connection refused surfaces differently but 502/504 possible), invalid payload rejected with 400, auth denied with 401/403, or endpoint version mismatch.","commonSituations":"AGENTMEMORY_URL points at a stale port; the daemon crashed or was upgraded so the route no longer exists (404); a proxy returns 502; the CLI version sends fields the daemon rejects.","solutions":["Read the status and body suffix in the message to identify the server-side cause (404 = wrong path/version, 400 = bad payload, 401 = auth).","Verify the daemon is running and the base URL/port matches (check AGENTMEMORY_URL or the default localhost endpoint with curl).","Confirm CLI and daemon versions match; restart the daemon after upgrading.","Retry the command once the daemon responds correctly; for transient 5xx add retry logic around the call."],"exampleFix":"// before\nawait post(`${base}/agentmemory/events`, payload);\n// after\ntry {\n  await post(`${base}/agentmemory/events`, payload);\n} catch (e) {\n  console.error('daemon request failed, is agentmemory running at', base, e.message);\n}","handlingStrategy":"try-catch","validationCode":"const url = new URL(base + path);\nif (!/^https?:$/.test(url.protocol)) throw new Error('bad URL');","typeGuard":null,"tryCatchPattern":"try {\n  const data = await post(url, body);\n} catch (e) {\n  if (e.message.includes(' 401 ')) handleAuthError();\n  else if (e.message.includes(' 404 ')) handleVersionMismatch();\n  else if (/ 5\\d\\d /.test(e.message)) scheduleRetry();\n  else throw e;\n}","preventionTips":["Health-check the daemon (GET /health) before issuing POSTs.","Pin CLI and daemon to matching versions.","Log the full error including the embedded response body suffix.","Wrap daemon calls in a helper with bounded retry for 5xx only."],"tags":["http","network","cli","rest-api"],"backgroundTag":"http-post-failed-non-2xx","analyzedSha":"e04ba88819c365c9acf9d6661ea802143e728bd6","analyzedAt":"2026-08-30T01:07:40.754Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}