{"record":{"id":"d53325b21c924fb7","repo":"clockworklabs/SpacetimeDB","slug":"publish-failed-with-http","errorCode":null,"errorMessage":"Publish failed with HTTP {}","messagePattern":"Publish failed with HTTP (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/cli/src/subcommands/publish.rs","lineNumber":775,"sourceCode":"        if let Some(org) = org {\n            builder = builder.query(&[(\"org\", org)]);\n        }\n\n        println!(\"Publishing module...\");\n\n        builder = add_auth_header_opt(builder, &auth_header);\n\n        // Set the host type.\n        builder = builder.query(&[(\"host_type\", host_type)]);\n\n        let (content_type, payload) =\n            publication_body(&module_schema, program_bytes, environment.values, environment_options)?;\n        let res = builder\n            .header(reqwest::header::CONTENT_TYPE, content_type)\n            .body(payload)\n            .send()\n            .await?;\n        anyhow::ensure!(res.status().is_success(), \"Publish failed with HTTP {}\", res.status());\n        let response: PublishResult = res\n            .json()\n            .await\n            .map_err(|_| anyhow::anyhow!(\"Invalid publish response\"))?;\n        match response {\n            PublishResult::Success {\n                domain,\n                database_identity,\n                op,\n            } => {\n                let op = match op {\n                    PublishOp::Created => \"Created new\",\n                    PublishOp::Updated => \"Updated\",\n                };\n                if let Some(ref domain) = domain {\n                    println!(\"{op} database with name: {domain}, identity: {database_identity}\");\n                } else {\n                    println!(\"{op} database with identity: {database_identity}\");","sourceCodeStart":757,"sourceCodeEnd":793,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/eddf9f5014579a50d4b67630e28b6e15cad9c4af/crates/cli/src/subcommands/publish.rs#L757-L793","documentation":"`execute_publish_configs` POSTs the compiled module and environment payload to the server, then requires the HTTP response to be a success status via `ensure!`. Any non-2xx response (authentication failure, invalid module, name conflicts, server errors, proxy errors) aborts the publish with this message including the status code.","triggerScenarios":"Publishing a module that fails server-side validation (HTTP 422/500), publishing with expired/invalid credentials (401/403), publishing to a database name you don't own (PermissionDenied), or hitting a proxy/CDN error page.","commonSituations":"Expired login token after a period of inactivity; a database already published by another identity; server version older than the CLI and rejects the payload; reverse proxy returning 502/503.","solutions":["Read the printed HTTP status: 401/403 → re-authenticate (`spacetime login`), 4xx → fix the request (module errors, name conflicts), 5xx → server-side problem.","Re-run `spacetime login` to refresh credentials, then retry the publish.","Check the server is running the expected version and inspect its logs for the rejection reason.","Verify network path/proxy isn't intercepting the request (status like 502/504 suggests infrastructure)."],"exampleFix":"// before\nspacetime publish --server https://prod.example mydb\n// error: Publish failed with HTTP 401 Unauthorized\n// after\nspacetime login --server https://prod.example\nspacetime publish --server https://prod.example mydb","handlingStrategy":"try-catch","validationCode":"// shell pre-flight\nspacetime login show --server \"$SERVER\" >/dev/null || spacetime login --server \"$SERVER\"","typeGuard":null,"tryCatchPattern":"// rust\nmatch publish().await {\n    Err(e) if e.to_string().contains(\"Publish failed with HTTP\") => {\n        if e.to_string().contains(\"401\") || e.to_string().contains(\"403\") {\n            relogin().await?; retry_publish().await\n        } else { Err(e) }\n    }\n    other => other,\n}","preventionTips":["Refresh credentials (`spacetime login`) before long-running CI publishes.","Publish to a local/test server first to catch module-level rejections.","Check ownership of the database name before publishing to shared servers."],"tags":["http","publish","cli","server-response"],"backgroundTag":"http-error-response","analyzedSha":"eddf9f5014579a50d4b67630e28b6e15cad9c4af","analyzedAt":"2026-09-20T12:15:59.611Z","contentChangedAt":"2026-09-20T12:15:59.611Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}