{"record":{"id":"b0e5937619ad2be2","repo":"JuliusBrussee/caveman","slug":"caveman-remote-gateway-key-revocation-failed-htt","errorCode":null,"errorMessage":"caveman: remote gateway key revocation failed (HTTP ${response.status}); credentials kept — retry `caveman logout`","messagePattern":"caveman: remote gateway key revocation failed \\(HTTP (.+?)\\); credentials kept — retry `caveman logout`","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cli/src/index.ts","lineNumber":9815,"sourceCode":"\tconst cfg = await config();\n\tconst externalToken = Boolean(process.env.CAVE_TOKEN);\n\tif (cfg.token && (!cfg.logoutPendingLocalCleanup || externalToken)) {\n\t  if (cfg.projectId && cfg.gatewayKeyId) {\n\t    let response: Response;\n\t    try {\n\t      response = await fetch(`${cfg.baseURL}/api/v1/projects/${encodeURIComponent(cfg.projectId)}/keys/${encodeURIComponent(cfg.gatewayKeyId)}/revoke`, {\n\t        method: \"POST\",\n\t        headers: { authorization: `Bearer ${cfg.token}`, \"content-type\": \"application/json\", \"x-cave-csrf\": \"cli\" },\n\t        body: \"{}\",\n\t        signal: AbortSignal.timeout(5000),\n\t      });\n\t    } catch {\n\t      throw new Error(\"caveman: remote gateway key revocation was unavailable; credentials kept — retry `caveman logout`\");\n\t    }\n\t    if (!response.ok) {\n\t      const body = await response.json().catch(() => null) as { error?: { code?: unknown } } | null;\n\t      const alreadyRevoked = response.status === 404 && body?.error?.code === \"cave_key_not_found\";\n\t      if (!alreadyRevoked) throw new Error(`caveman: remote gateway key revocation failed (HTTP ${response.status}); credentials kept — retry \\`caveman logout\\``);\n\t    }\n\t  }\n\t  const headers: Record<string, string> = {\n\t    authorization: `Bearer ${cfg.token}`,\n\t    \"x-cave-client\": \"cli\",\n\t  };\n\t  const request: RequestInit = {\n\t    method: \"POST\",\n\t    redirect: \"manual\",\n\t    headers,\n\t    signal: AbortSignal.timeout(5000),\n\t  };\n\t  if (cfg.refreshToken) {\n\t    headers[\"content-type\"] = \"application/json\";\n\t    request.body = JSON.stringify({ refresh_token: cfg.refreshToken });\n\t  }\n\t  let response: Response;\n\t  try {","sourceCodeStart":9797,"sourceCodeEnd":9833,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/cli/src/index.ts#L9797-L9833","documentation":"Thrown during `caveman logout` when the remote gateway key revocation endpoint returns a non-2xx status that is not the tolerated 404 `cave_key_not_found` case. Local credentials are kept so logout can be retried safely.","triggerScenarios":"`caveman logout` while the revocation endpoint responds 401 (expired/invalid token), 403, 500, 429 etc. — any failure status except 404 with error code `cave_key_not_found`.","commonSituations":"Access token expired before logout; gateway returning 5xx during an incident; rate limiting (429); revoked key via another device but server returning a different 404 body shape.","solutions":["Read the HTTP status in the message; for 401, re-authenticate (`caveman login`) then retry logout.","Retry `caveman logout` after the gateway recovers (5xx) or the rate limit resets (429).","If the server 404s with a different error code shape, verify gateway API version compatibility.","Credentials are kept locally, so a simple retry is always safe."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await logout();\n} catch (e) {\n  if (e instanceof Error) {\n    const m = e.message.match(/revocation failed \\(HTTP (\\d+)\\)/);\n    if (m && m[1] === \"401\") console.error(\"Token already invalid; login again before retrying logout.\");\n    else if (m && (m[1] === \"503\" || m[1] === \"429\")) console.error(\"Gateway temporarily failing/rate-limited; retry logout later.\");\n    else throw e;\n  }\n}","preventionTips":["Log out before the access token expires to avoid 401s.","Avoid logging out during gateway deploys or incidents (5xx).","Keep CLI and gateway API versions aligned."],"tags":["http","logout","api","credentials"],"backgroundTag":"http-error-response","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}