expression
Inspect status before decoding
Build a synthetic response with the http crate and convert it to Reqwest’s response type. Inspect status and classify HTTP errors without a server. error_for_status_ref rejects client and server error classes; applications may require a stricter success policy. External crate example; constructs requests or synthetic responses in memory; no request is sent. Expected stdout (not executed): true 404 Common mistake: Treating successful transport as proof of a successful HTTP status.
Formal Syntax & Structure
rust syntaxrust
response.status(); response.error_for_status_ref()Working Example
Example Snippetrust
#[tokio::main(flavor = "current_thread")]async fn main() { let raw = http::Response::builder().status(404).body("missing").unwrap(); let r: reqwest::Response = raw.into(); let err = r.error_for_status_ref().unwrap_err(); println!("{} {}", err.is_status(), err.status().unwrap().as_u16());}