{"id":"fbfad586e94b6d42","repo":"seanmonstar/reqwest","slug":"request-or-response-body-error","errorCode":null,"errorMessage":"request or response body error","messagePattern":"request or response body error","errorType":"exception","errorClass":"reqwest::Error","httpStatus":null,"severity":"error","filePath":"src/error.rs","lineNumber":349,"sourceCode":"    Request,\n    Redirect,\n    #[cfg(not(all(target_arch = \"wasm32\", any(target_os = \"unknown\", target_os = \"none\"))))]\n    Status(StatusCode, Option<hyper::ext::ReasonPhrase>),\n    #[cfg(all(target_arch = \"wasm32\", any(target_os = \"unknown\", target_os = \"none\")))]\n    Status(StatusCode),\n    Body,\n    Decode,\n    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","sourceCodeStart":331,"sourceCodeEnd":367,"githubUrl":"https://github.com/seanmonstar/reqwest/blob/17e9bcb51c46edebfb6f5f2f5184b51dac4b3a7d/src/error.rs#L331-L367","documentation":"The `Kind::Body` error from `error::body(...)` (error.rs:348-350). It fires when reading or writing the streaming body fails — most commonly a body read/write timeout (body.rs:309 and body.rs:352 wrap `TimedOut`), or an h3 pool stream body error (pool.rs:343/351).","triggerScenarios":"A request body upload or response body download exceeding the client/per-request `.timeout()`; the peer resets the stream mid-body; the response stream yields an h3/hyper body error during `.bytes()`/`.text()`/streaming.","commonSituations":"Large file upload over a slow link with a tight `.timeout(Duration::from_secs(5))`; streaming a huge JSON response that stalls; slow mobile network where the body never finishes in time; server closes the connection while you're still reading.","solutions":["Raise or remove the timeout for large transfers: `.timeout(Duration::from_secs(300))` or per-request `.request_timeout`.","Use `error.is_timeout()` to distinguish a body timeout from a genuine I/O failure and retry only timeouts.","Stream the body in chunks instead of buffering, so progress resets the timeout window if using a per-byte deadline.","Inspect `e.source()` for the underlying hyper/h3/io error to confirm it's not a real protocol failure."],"exampleFix":"// before\nlet client = Client::builder().timeout(Duration::from_secs(5)).build()?;\nlet bytes = client.get(url).send().await?.bytes().await?; // body timeout on big payload\n\n// after\nlet client = Client::builder().timeout(Duration::from_secs(120)).build()?;\nlet bytes = client.get(url).send().await?.bytes().await?;","handlingStrategy":"retry","validationCode":"// No body-size pre-check, but size the timeout to the payload.\nlet timeout = estimate_timeout(payload_len, link_bps);\nlet client = Client::builder().timeout(timeout).build()?;\n","typeGuard":"fn is_body_or_body_timeout(e: &reqwest::Error) -> bool { e.is_body() || (e.is_timeout() && e.is_body()) }\n","tryCatchPattern":"match resp.bytes().await {\n    Ok(b) => Ok(b),\n    Err(e) if e.is_timeout() => retry().await,\n    Err(e) if e.is_body() => Err(anyhow!(\"body error: {}\", e.source().map(|s| s.to_string()).unwrap_or_default())),\n    Err(e) => Err(e.into()),\n}","preventionTips":["Set timeouts proportional to expected payload size and link speed.","Stream large bodies in chunks to surface progress.","Distinguish is_timeout() from genuine body failures before retrying."],"tags":["body","timeout","network","streaming"],"analyzedSha":"17e9bcb51c46edebfb6f5f2f5184b51dac4b3a7d","analyzedAt":"2026-08-06T01:23:05.134Z","schemaVersion":2}