seanmonstar/reqwest · error · reqwest::Error
HTTP status server error ({code})
Error message
HTTP status server error ({code}) What it means
A `Kind::Status(5xx, ...)` error (error.rs:280-296). Produced only by `Response::error_for_status()` (response.rs:382, 413) when the server returned a 5xx server-error status. Like the 4xx variant, it requires the caller to explicitly convert the status.
Source
Thrown at src/error.rs:373
pub(crate) fn request<E: Into<BoxError>>(e: E) -> Error {
Error::new(Kind::Request, Some(e))
}
pub(crate) fn dns<E: Into<BoxError>>(e: E) -> BoxError {
Box::new(DnsError { inner: e.into() })
}
pub(crate) fn redirect<E: Into<BoxError>>(e: E, url: Url) -> Error {
Error::new(Kind::Redirect, Some(e)).with_url(url)
}
pub(crate) fn status_code(
url: Url,
status: StatusCode,
#[cfg(not(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none"))))] reason: Option<hyper::ext::ReasonPhrase>,
) -> Error {
Error::new(
Kind::Status(
status,
#[cfg(not(all(
target_arch = "wasm32",
any(target_os = "unknown", target_os = "none")
)))]
reason,
),
None::<Error>,
)
.with_url(url)
}
pub(crate) fn url_bad_scheme(url: Url) -> Error {
Error::new(Kind::Builder, Some(BadScheme)).with_url(url)
}
pub(crate) fn url_invalid_uri(url: Url) -> Error {View on GitHub (pinned to 17e9bcb51c)
Solutions
- Retry 5xx with exponential backoff + jitter; treat 503 with `Retry-After` specially.
- Distinguish from 4xx: `status.is_server_error()` should retry, `is_client_error()` usually should not.
- Read the body for diagnostics before retrying; log the request id header.
Example fix
// before
let body: T = resp.error_for_status()?.json().await?; // crashes on transient 503
// after
if resp.status().is_server_error() {
return Err(Retryable::Server(resp.status()).into()); // retried by outer loop
}
let body: T = resp.error_for_status()?.json().await?; Defensive patterns
Strategy: retry
Validate before calling
// Decide retryability from the status before failing.
let status = resp.status();
if status.is_server_error() { return Err(Retryable(status).into()); }
Type guard
fn is_server_status(e: &reqwest::Error) -> bool {
e.status().map(|c| c.is_server_error()).unwrap_or(false)
}
Try / catch
let resp = client.get(&url).send().await?;
if resp.status().is_server_error() {
return Err(Retryable::Server(resp.status()).into()); // outer loop backs off
}
let body: T = resp.json().await?; Prevention
- Retry 5xx with exponential backoff + jitter; honor Retry-After on 503.
- Log the request id / trace id header before retrying so duplicates are traceable.
- Circuit-break after repeated 5xx to avoid hammering a degraded upstream.
When it happens
Trigger: Calling `resp.error_for_status()?` after a 500/502/503/504 response.
Common situations: Upstream service down or crashing (500), bad gateway from a reverse proxy (502), service temporarily unavailable / deploying (503), gateway timeout (504). These are usually transient and worth retrying.
Related errors
AI-assisted analysis of seanmonstar/reqwest@17e9bcb51c (2026-08-06).
Data as JSON: /data/errors/ba238187d8efffda.json.
Report an issue: GitHub.