{"record":{"id":"963fa1854aea48b9","repo":"Hmbown/CodeWhale","slug":"codewhale-account-request-failed-http-code-c","errorCode":null,"errorMessage":"Codewhale account request failed (HTTP {}, code {code})","messagePattern":"Codewhale account request failed \\(HTTP (.+?), code (.+?)\\)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/cli/src/cloud.rs","lineNumber":1260,"sourceCode":"fn parse_json_body<T: DeserializeOwned>(body: &[u8]) -> Result<T> {\n    serde_json::from_slice(body).context(\"The Codewhale service returned an invalid JSON response\")\n}\n\nfn response_error(response: &CloudResponse) -> anyhow::Error {\n    let code = serde_json::from_slice::<serde_json::Value>(&response.body)\n        .ok()\n        .and_then(|body| {\n            body.get(\"code\")\n                .and_then(serde_json::Value::as_str)\n                .or_else(|| {\n                    body.get(\"error\")\n                        .and_then(|error| error.get(\"code\"))\n                        .and_then(serde_json::Value::as_str)\n                })\n                .and_then(safe_error_code)\n        });\n    match code {\n        Some(code) => anyhow!(\n            \"Codewhale account request failed (HTTP {}, code {code})\",\n            response.status\n        ),\n        None => anyhow!(\n            \"Codewhale account request failed (HTTP {})\",\n            response.status\n        ),\n    }\n}\n\nfn safe_error_code(code: &str) -> Option<String> {\n    if code.is_empty()\n        || code.len() > 80\n        || !code\n            .bytes()\n            .all(|byte| byte.is_ascii_alphanumeric() || matches!(byte, b'_' | b'-' | b'.'))\n    {\n        return None;","sourceCodeStart":1242,"sourceCodeEnd":1278,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/crates/cli/src/cloud.rs#L1242-L1278","documentation":"A request to the Codewhale account API returned a non-success HTTP status, and the response body carried a parseable machine error code string (extracted from the JSON `code` field and passed through `safe_error_code`). The CLI surfaces both the HTTP status and that error code so the developer can identify the server-side failure.","triggerScenarios":"Any account API call (list providers, create key, resolve models) that gets an HTTP error response whose JSON body contains a `code` string field recognized by `safe_error_code`.","commonSituations":"Expired/invalid account key (401/403 with an error code), rate limiting, requesting a nonexistent resource, or server-side validation errors returned as JSON with `code`.","solutions":["Read the `code` in the message and look it up in the Codewhale account API docs.","Re-authenticate (`codewhale login`) or refresh the machine API key if the status is 401/403.","Retry with backoff if the code indicates rate limiting (429).","Check the Codewhale status page / contact support for 5xx statuses."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"HTTP 401\") || e.to_string().contains(\"HTTP 403\") => reauthenticate_and_retry(),\n    Err(e) if e.to_string().contains(\"HTTP 429\") => backoff_and_retry(),\n    Err(e) => return Err(e),\n    Ok(v) => Ok(v),\n}","preventionTips":["Refresh the account key before it expires.","Wrap account API calls in retry-with-backoff for 429/5xx statuses."],"tags":["http","api","cloud"],"backgroundTag":"http-error-response","analyzedSha":"433685b2024e7bc4c99e1e2e326bcad39b4d9d65","analyzedAt":"2026-09-15T12:24:24.634Z","contentChangedAt":"2026-09-15T12:24:24.634Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}