{"id":"6db236d5cad22c5e","repo":"seanmonstar/reqwest","slug":"error-sending-request-6db236","errorCode":null,"errorMessage":"error sending request","messagePattern":"error sending request","errorType":"exception","errorClass":"reqwest::Error","httpStatus":null,"severity":"error","filePath":"src/error.rs","lineNumber":357,"sourceCode":"    Upgrade,\n}\n\n// constructors\n\npub(crate) fn builder<E: Into<BoxError>>(e: E) -> Error {\n    Error::new(Kind::Builder, Some(e))\n}\n\npub(crate) fn body<E: Into<BoxError>>(e: E) -> Error {\n    Error::new(Kind::Body, Some(e))\n}\n\npub(crate) fn decode<E: Into<BoxError>>(e: E) -> Error {\n    Error::new(Kind::Decode, Some(e))\n}\n\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,","sourceCodeStart":339,"sourceCodeEnd":375,"githubUrl":"https://github.com/seanmonstar/reqwest/blob/17e9bcb51c46edebfb6f5f2f5184b51dac4b3a7d/src/error.rs#L339-L375","documentation":"The generic `Kind::Request` error from `error::request(...)` (error.rs:356-358). It is the catch-all 'could not send the request' error, used for both the overall request/client timeout (client.rs:3094/3102 wrap `TimedOut`) and the actual transport failure when polling the hyper service (client.rs:3117).","triggerScenarios":"Client/per-request timeout elapses before a response begins (client.rs:3094, 3102); hyper fails to connect, DNS fails, TLS handshake fails, connection reset, or the connector returns an error (client.rs:3117).","commonSituations":"Host unreachable / typo'd domain → DNS error; firewall blocking the port; TLS cert mismatch; `.timeout()` too short so the request never completes; server too slow to respond within the deadline.","solutions":["Branch on `e.is_timeout()` vs `e.is_connect()` vs `e.is_dns()` to pick the right recovery.","For timeouts, raise `.timeout()` or add retry with exponential backoff.","For DNS/connect, verify the URL, network egress, and TLS roots; print `e.source()` for the hyper/hickory error.","Use a shorter connect timeout separately from the overall timeout to fail fast on unreachable hosts."],"exampleFix":"// before\nlet resp = client.get(url).send().await?; // 'error sending request', cause unknown\n\n// after\nmatch client.get(url).send().await {\n    Ok(r) => Ok(r),\n    Err(e) => {\n        if e.is_timeout() { retry(/* ... */).await }\n        else if e.is_connect() || e.is_dns() { return Err(anyhow!(\"unreachable: {}\", e)); }\n        else { return Err(e.into()); }\n    }\n}","handlingStrategy":"retry","validationCode":"// No general pre-check; validate URL + DNS reachability for deterministic cases.\nlet url = url::Url::parse(&raw)?;\nif !matches!(url.scheme(), \"http\" | \"https\") { return Err(anyhow!(\"bad scheme\")); }\nif let Some(host) = url.host_str() { /* optional DNS probe */ }\n","typeGuard":"fn classify(e: &reqwest::Error) -> &'static str {\n    if e.is_timeout() { \"timeout\" }\n    else if e.is_connect() { \"connect\" }\n    else if e.is_dns() { \"dns\" }\n    else if e.is_request() { \"request\" }\n    else { \"other\" }\n}\n","tryCatchPattern":"match client.get(&url).send().await {\n    Ok(r) => Ok(r),\n    Err(e) if e.is_timeout() || e.is_connect() => backoff_retry().await,\n    Err(e) if e.is_dns() => Err(anyhow!(\"unreachable host\")),\n    Err(e) => Err(e.into()),\n}","preventionTips":["Use separate connect and overall timeouts to fail fast on unreachable hosts.","Wrap send() in retry with classification, not bare ?.","Surface e.source() in logs so the hyper/DNS cause is visible."],"tags":["request","timeout","network","connect"],"analyzedSha":"17e9bcb51c46edebfb6f5f2f5184b51dac4b3a7d","analyzedAt":"2026-08-06T01:23:05.134Z","schemaVersion":2}