{"record":{"id":"e2d67836e062eca2","repo":"gitbutlerapp/gitbutler","slug":"download-of-url-failed-with-http-status-respon","errorCode":null,"errorMessage":"Download of {url} failed with HTTP status: {response_code}","messagePattern":"Download of (.+?) failed with HTTP status: (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-installer/src/download.rs","lineNumber":37,"sourceCode":"    {\n        let mut transfer = easy.transfer();\n        transfer\n            .write_function(|data| {\n                buf.borrow_mut().extend_from_slice(data);\n                Ok(data.len())\n            })\n            .context(\"Failed to set write function\")?;\n\n        transfer\n            .perform()\n            .with_context(|| format!(\"Failed to download from {url}\"))?;\n    }\n\n    let response_code = easy\n        .response_code()\n        .context(\"Failed to get response code\")?;\n    if response_code != 200 {\n        bail!(\"Download of {url} failed with HTTP status: {response_code}\");\n    }\n\n    let effective_url = easy\n        .effective_url()\n        .context(\"Failed to get effective URL\")?\n        .ok_or_else(|| anyhow!(\"Effective URL is missing\"))?;\n\n    crate::release::validate_download_url(effective_url)\n        .with_context(|| format!(\"Download was redirected to an untrusted URL: {effective_url}\"))?;\n\n    String::from_utf8(buf.into_inner()).context(\"Signature file is not valid UTF-8\")\n}\n\npub(crate) fn download_file(url: &str, dest: &Path) -> Result<()> {\n    let mut easy = create_client()?;\n\n    easy.url(url)\n        .with_context(|| format!(\"Failed to set URL: {url}\"))?;","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-installer/src/download.rs#L19-L55","documentation":"`download_to_string` uses curl (curl::easy) to fetch a URL and requires an HTTP 200 response. Any other status (3xx terminal redirects that curl did not follow, 4xx/5xx) makes it bail with the URL and status code so the caller knows the content fetch failed.","triggerScenarios":"Calling download_and_install_app / download_to_string with a URL that returns non-200: a manifest or metadata URL that 404s because the version does not exist, a 503 from a CDN outage, or a 401 on a resource requiring auth.","commonSituations":"Requesting metadata for an unpublished but version; transient CDN/server errors; firewalls or proxies returning an HTML error page; URL typos producing 404s.","solutions":["Check the URL and requested version — confirm the artifact/metadata actually exists (HTTP status 404 usually means the version was never published).","Retry the download after a delay; 5xx codes are often transient.","Check network/proxy configuration if statuses like 403/502 appear unexpectedly.","Inspect the response body outside this helper if you need the server's error detail — this bail only surfaces the code."],"exampleFix":"// before\nlet manifest = download_to_string(&manifest_url)?;\n// after\nlet manifest = match download_to_string(&manifest_url) {\n    Ok(m) => m,\n    Err(e) if e.to_string().contains(\"HTTP status: 5\") => {\n        std::thread::sleep(Duration::from_secs(3));\n        download_to_string(&manifest_url)?\n    }\n    Err(e) => return Err(e),\n};","handlingStrategy":"retry","validationCode":"let resp = reqwest::blocking::get(url)?;\nif !resp.status().is_success() {\n    anyhow::bail!(\"pre-check failed for {url}: {}\", resp.status());\n}","typeGuard":null,"tryCatchPattern":"match download_to_string(&url) {\n    Ok(s) => s,\n    Err(e) if e.to_string().contains(\"HTTP status: 5\") => retry_with_backoff(3, || download_to_string(&url))?,\n    Err(e) => return Err(anyhow!(\"download failed, check URL/version: {e:#}\")),\n}","preventionTips":["Pre-flight the URL with a lightweight HEAD/GET before downloading the full payload.","Retry on transient 5xx with exponential backoff; fail fast on 4xx.","Validate the requested version string against a published versions list before building the URL.","Log the URL alongside the error so typos are obvious."],"tags":["network","http","download"],"backgroundTag":"http-non-200-response","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}