{"record":{"id":"88ccdbae00076ba2","repo":"tursodatabase/turso","slug":"request-failed-status-text","errorCode":null,"errorMessage":"request failed: {status} {text}","messagePattern":"request failed: (.+?) (.+?)","errorType":"http","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"bindings/rust/src/sync.rs","lineNumber":1127,"sourceCode":"        );\n        assert_eq!(\n            Builder::new_remote(\":memory:\")\n                .with_logical_mvcc_pull(false)\n                .logical_mvcc_pull,\n            Some(false)\n        );\n    }\n\n    async fn handle_response(resp: reqwest::Response) -> Result<()> {\n        let status = resp.status();\n        let text = resp.text().await.unwrap_or_default();\n\n        if status == 400 && text.contains(\"already exists\") {\n            return Ok(());\n        }\n\n        if !status.is_success() {\n            return Err(anyhow!(\"request failed: {status} {text}\"));\n        }\n\n        Ok(())\n    }\n\n    pub struct TursoServer {\n        user_url: String,\n        db_url: String,\n        host: String,\n        db_prefix: String,\n        server: Option<Child>,\n        _sync_dir_created_by_harness: Option<TempDir>,\n        client: Client,\n    }\n\n    impl TursoServer {\n        pub async fn new() -> Result<Self> {\n            let client = Client::new();","sourceCodeStart":1109,"sourceCodeEnd":1145,"githubUrl":"https://github.com/tursodatabase/turso/blob/492c4a71cd7c2649e7df83da1471b74f4b1c7aa9/bindings/rust/src/sync.rs#L1109-L1145","documentation":"Raised by the test-harness HTTP client in bindings/rust/src/sync.rs when a request to the sync server returns a non-success status. handle_response treats HTTP 400 with a body containing 'already exists' as success (idempotent create); every other failing status becomes this error with the status code and full response body embedded.","triggerScenarios":"POSTing a create/upload request that fails server-side without 'already exists' in the body; hitting a renamed or removed route (404); auth failure (401/403); malformed JSON payload after a sync-protocol schema change (400 without that phrase); server bug returning 500.","commonSituations":"Client harness and tursodb sync server built from different commits so routes or payload schemas disagree; server crashed mid-test and a proxy returns an error status; typos in the URL path used by a custom harness.","solutions":["Read the status and body in the message: 404 means wrong path, 400 means payload, 500 means a server-side bug to chase in the server log","Check the sync server's stdout/stderr for the panic or error that produced the status","Rebuild both the server binary and the bindings crate from the same commit so routes and payloads match","For transient 5xx, rerun the test; for 4xx, fix the request path or payload"],"exampleFix":"// before\nlet resp = client.post(url).json(&body).send().await?;\nhandle_response(resp).await?; // opaque: request failed: 500 ...\n\n// after\nlet resp = client.post(url).json(&body).send().await?;\nlet status = resp.status();\nlet text = resp.text().await.unwrap_or_default();\nif !status.is_success() && !(status == 400 && text.contains(\"already exists\")) {\n    anyhow::bail!(\"create failed: {status} body: {text}\");\n}","handlingStrategy":"try-catch","validationCode":"let resp = client.get(format!(\"{user_url}/health\")).send().await?;\nanyhow::ensure!(resp.status().is_success(), \"sync server unhealthy before request\");","typeGuard":null,"tryCatchPattern":"match handle_response(resp).await {\n    Ok(()) => {}\n    Err(e) => {\n        let msg = e.to_string();\n        if msg.contains(\"500\") || msg.contains(\"503\") { /* retry with backoff */ }\n        else { return Err(e); }\n    }\n}","preventionTips":["Build the HTTP client harness and the sync server from the same commit","Log the response body verbatim on failure - the status alone is not enough","Treat 400 'already exists' as success for idempotent creates, as the harness does"],"tags":["sync","http-client","test-harness","status-code","rust"],"backgroundTag":"http-error-response","analyzedSha":"492c4a71cd7c2649e7df83da1471b74f4b1c7aa9","analyzedAt":"2026-08-20T07:02:18.389Z","contentChangedAt":"2026-08-20T07:02:18.389Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}