{"record":{"id":"8d91d24b94b4f974","repo":"Hmbown/CodeWhale","slug":"codewhale-account-request-failed-http-status-code-code","errorCode":null,"errorMessage":"Codewhale account request failed (HTTP {status}, code {code})","messagePattern":"Codewhale account request failed \\(HTTP (.+?), code (.+?)\\)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/cli/src/cloud.rs","lineNumber":1296,"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":1278,"sourceCodeEnd":1314,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/cli/src/cloud.rs#L1278-L1314","documentation":"Generic handler for failed HTTP responses from the Codewhale account API. When the response body carries a machine-readable `code` field (passed through `safe_error_code`), the error includes both the HTTP status and that code so the developer can identify the exact API-side failure.","triggerScenarios":"Any account API request (login, key management, provider config) that returns a non-success status with a JSON error body containing a `code` string.","commonSituations":"401 with `invalid_api_key`, 403 with `forbidden`, 404 with `not_found`, 409 with a conflict code from the account service; expired or revoked API keys.","solutions":["Read the `code` in the message and map it to the documented account API error.","Re-authenticate: `codewhale login` or set MACHINE_KEY_ENV with a fresh key (`codewhale account api-keys create`).","Retry later if the status is 5xx; check the Codewhale service status for outages."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"code invalid_api_key\") => reauthenticate(),\n    Err(e) => log::error(\"account request failed: {e}\"),\n    Ok(v) => v,\n}","preventionTips":["Rotate API keys before expiry.","Handle 401/403 centrally with a re-login flow.","Log the status+code pair for diagnostics."],"tags":["http","api","cloud"],"backgroundTag":"api-error-response","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-22T10:30:35.592Z"}