{"id":"ba238187d8efffda","repo":"seanmonstar/reqwest","slug":"http-status-server-error-code","errorCode":null,"errorMessage":"HTTP status server error ({code})","messagePattern":"HTTP status server error \\((.+?)\\)","errorType":"http","errorClass":"reqwest::Error","httpStatus":null,"severity":"error","filePath":"src/error.rs","lineNumber":373,"sourceCode":"\npub(crate) fn request<E: Into<BoxError>>(e: E) -> Error {\n    Error::new(Kind::Request, Some(e))\n}\n\npub(crate) fn dns<E: Into<BoxError>>(e: E) -> BoxError {\n    Box::new(DnsError { inner: e.into() })\n}\n\npub(crate) fn redirect<E: Into<BoxError>>(e: E, url: Url) -> Error {\n    Error::new(Kind::Redirect, Some(e)).with_url(url)\n}\n\npub(crate) fn status_code(\n    url: Url,\n    status: StatusCode,\n    #[cfg(not(all(target_arch = \"wasm32\", any(target_os = \"unknown\", target_os = \"none\"))))] reason: Option<hyper::ext::ReasonPhrase>,\n) -> Error {\n    Error::new(\n        Kind::Status(\n            status,\n            #[cfg(not(all(\n                target_arch = \"wasm32\",\n                any(target_os = \"unknown\", target_os = \"none\")\n            )))]\n            reason,\n        ),\n        None::<Error>,\n    )\n    .with_url(url)\n}\n\npub(crate) fn url_bad_scheme(url: Url) -> Error {\n    Error::new(Kind::Builder, Some(BadScheme)).with_url(url)\n}\n\npub(crate) fn url_invalid_uri(url: Url) -> Error {","sourceCodeStart":355,"sourceCodeEnd":391,"githubUrl":"https://github.com/seanmonstar/reqwest/blob/17e9bcb51c46edebfb6f5f2f5184b51dac4b3a7d/src/error.rs#L355-L391","documentation":"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.","triggerScenarios":"Calling `resp.error_for_status()?` after a 500/502/503/504 response.","commonSituations":"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.","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."],"exampleFix":"// before\nlet body: T = resp.error_for_status()?.json().await?; // crashes on transient 503\n\n// after\nif resp.status().is_server_error() {\n    return Err(Retryable::Server(resp.status()).into()); // retried by outer loop\n}\nlet body: T = resp.error_for_status()?.json().await?;","handlingStrategy":"retry","validationCode":"// Decide retryability from the status before failing.\nlet status = resp.status();\nif status.is_server_error() { return Err(Retryable(status).into()); }\n","typeGuard":"fn is_server_status(e: &reqwest::Error) -> bool {\n    e.status().map(|c| c.is_server_error()).unwrap_or(false)\n}\n","tryCatchPattern":"let resp = client.get(&url).send().await?;\nif resp.status().is_server_error() {\n    return Err(Retryable::Server(resp.status()).into()); // outer loop backs off\n}\nlet body: T = resp.json().await?;","preventionTips":["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."],"tags":["status","http","server-error","retry"],"analyzedSha":"17e9bcb51c46edebfb6f5f2f5184b51dac4b3a7d","analyzedAt":"2026-08-06T01:23:05.134Z","schemaVersion":2}