gitbutlerapp/gitbutler · error
Server returned error
Error message
Server returned error: {e} What it means
Thrown when the update server responds with an HTTP error status (4xx/5xx); error_for_status() converts the successful transport response into an error carrying the status code and URL. The request reached the server but the server rejected or failed to process it.
Solutions
- Inspect the HTTP status in the wrapped reqwest error and match the fix to it (401/403 → re-authenticate; 4xx → check channel/version payload; 5xx → retry later).
- Re-login to refresh the gitbutler_access_token secret if the status is 401/403.
- Retry the update check after a short delay if the status is 5xx (server-side issue).
- Verify the build's CHANNEL/VERSION env vars are sane; a corrupt channel value can trigger client-side rejection.
Example fix
// before
let response = client.post(url).json(&request_body).send().await
.map_err(|e| anyhow::anyhow!("Request failed: {e}"))?
.error_for_status()
.map_err(|e| anyhow::anyhow!("Server returned error: {e}"))?;
// after: tolerate server errors and fall back to cached status
let response = match client.post(&url).json(&request_body).send().await {
Ok(r) => r,
Err(_) => return Ok(cached_status),
};
let response = match response.error_for_status() {
Ok(r) => r,
Err(err) if err.status().is_some_and(|s| s.is_server_error()) => return Ok(cached_status),
Err(e) => return Err(anyhow::anyhow!("Server returned error: {e}")),
}; Defensive patterns
Strategy: fallback
Try / catch
match but_update::check_status(app, &settings, &mut cache) {
Err(e) if e.to_string().contains("Server returned error") => {
// server rejected the request: use cached update status
Ok(cached_check_result())
}
other => other?,
} Prevention
- Keep the access token fresh (re-login when 401/403 occurs).
- Only send channel/os/arch/version values produced by the build system.
- Retry with backoff on 5xx instead of surfacing the error to users.
- Monitor server health before hard-failing the update flow.
When it happens
Trigger: check_status/check_status_with_url receiving a 4xx or 5xx response from the update endpoint — e.g. 401 when the X-Auth-Token from secret::retrieve("gitbutler_access_token") is missing/invalid, 400 for a malformed CheckUpdatesRequest (bad channel/os/arch/version), or 5xx during a server-side incident.
Common situations: Expired or revoked access token in the secret store; nightly channel builds hitting an endpoint that rejects the channel/os/arch combination; server outage returning 500/502/503; a stale build sending an unrecognized version string.
Understand the failure class
Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.
Related errors
- Anthropic API error ( )
- Error
- Failed to add labels
- Failed to add to GitHub stack
- Failed to create GitHub stack
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/bf05f9ed177bac21.
Report an issue: GitHub.
Appendix: source
Thrown at crates/but-update/src/check.rs:127
.build()?;
let url = url_override.unwrap_or(UPDATES_CHECK_URL).to_string();
let result = std::thread::spawn(move || -> anyhow::Result<CheckUpdateStatus> {
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.map_err(|e| anyhow::anyhow!("Failed to create runtime: {e}"))?;
runtime.block_on(async {
let response = client
.post(url)
.json(&request_body)
.send()
.await
.map_err(|e| anyhow::anyhow!("Request failed: {e}"))?
.error_for_status()
.map_err(|e| anyhow::anyhow!("Server returned error: {e}"))?;
let update_info = response
.json::<CheckUpdateStatus>()
.await
.map_err(|e| anyhow::anyhow!("Failed to parse response: {e}"))?;
Ok(update_info)
})
})
.join()
.map_err(|_| anyhow::anyhow!("Update check thread panicked"))?;
// Save to cache (convert to but_db types)
if let Ok(status) = &result {
let now = chrono::Utc::now();
// Get existing cache to preserve suppression
let existing = trans.update_check().get();View on GitHub (pinned to 58e5313667)