{"record":{"id":"2e9624c9823e9ab2","repo":"Hmbown/CodeWhale","slug":"translate-http-status-error-text","errorCode":null,"errorMessage":"translate: HTTP {status}: {error_text}","messagePattern":"translate: HTTP (.+?): (.+?)","errorType":"http","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/tui/src/client.rs","lineNumber":2867,"sourceCode":"        chat::apply_route_reasoning_controls(\n            &mut body,\n            self.api_provider,\n            &self.base_url,\n            &model,\n            Some(\"off\"),\n        );\n\n        self.apply_provider_routing(&mut body);\n        let response = self.send_json_with_retry(&url, &body).await?;\n        let status = response.status();\n        if !status.is_success() {\n            let raw_error_text = bounded_error_text(response, ERROR_BODY_MAX_BYTES).await;\n            let error_text = sanitize_http_error_body(\n                Some(self.api_provider.display_name()),\n                status.as_u16(),\n                &raw_error_text,\n            );\n            anyhow::bail!(\"translate: HTTP {status}: {error_text}\");\n        }\n\n        let value: serde_json::Value = response.json().await?;\n        let usage_reported = value\n            .get(\"usage\")\n            .and_then(Value::as_object)\n            .is_some_and(|usage| {\n                [\n                    \"input_tokens\",\n                    \"prompt_tokens\",\n                    \"output_tokens\",\n                    \"completion_tokens\",\n                    \"total_tokens\",\n                ]\n                .iter()\n                .any(|field| usage.contains_key(*field))\n            });\n        let usage = parse_usage(value.get(\"usage\"));","sourceCodeStart":2849,"sourceCodeEnd":2885,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/client.rs#L2849-L2885","documentation":"The translation HTTP call to the provider returned a non-success status; the client reads a bounded amount of the error body, sanitizes it, and surfaces it as `translate: HTTP {status}: {error_text}`. This is a generic wrapper around any provider-side HTTP error (4xx/5xx) during translation.","triggerScenarios":"Provider returns 401/403 (bad or missing API key), 429 (rate limit), 400 (bad request/model name), or 5xx (provider outage) on the translation endpoint.","commonSituations":"Expired or wrong API key for the translation provider; exceeding rate limits; wrong model name in translation config; provider regional outage.","solutions":["Read the status and sanitized error_text: 401/403 → fix the API key; 429 → retry with backoff; 400 → fix model name/payload; 5xx → wait and retry.","Verify the provider API key is set and valid for the translation endpoint.","Check the model name configured for translation exists on that provider.","If 5xx persists, check provider status page and retry later."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// pre-flight: verify key present and non-empty\nfn ensure_key(env: &str) -> Result<(), String> {\n    std::env::var(env).ok().filter(|k| !k.trim().is_empty()).ok_or_else(|| format!(\"{env} not set\"))\n}","typeGuard":null,"tryCatchPattern":"match result {\n    Err(e) if e.to_string().starts_with(\"translate: HTTP \") => {\n        if e.to_string().contains(\" 429 \") { backoff_retry().await?; }\n        else if e.to_string().contains(\" 401 \") { eprintln!(\"check translation provider API key\"); }\n        else { return Err(e); }\n    }\n    r => r?,\n}","preventionTips":["Validate the provider API key is set before translating.","Add exponential backoff for 429/5xx statuses.","Keep model names in config valid for the target provider.","Monitor provider status pages for outages."],"tags":["http","api-error","translation","network"],"backgroundTag":"http-error-response","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}