diff --git a/crates/nu-command/src/network/fetch.rs b/crates/nu-command/src/network/fetch.rs index 3f57b5222..ed2f5542c 100644 --- a/crates/nu-command/src/network/fetch.rs +++ b/crates/nu-command/src/network/fetch.rs @@ -450,7 +450,8 @@ fn helper( } } - match request.send() { + // Explicitly turn 4xx and 5xx statuses into errors. + match request.send().and_then(|r| r.error_for_status()) { Ok(resp) => match resp.headers().get("content-type") { Some(content_type) => { let content_type = content_type.to_str().map_err(|e| { diff --git a/crates/nu-command/src/network/post.rs b/crates/nu-command/src/network/post.rs index bdb486687..5c64c13fd 100644 --- a/crates/nu-command/src/network/post.rs +++ b/crates/nu-command/src/network/post.rs @@ -304,7 +304,8 @@ fn helper( } } - match request.send() { + // Explicitly turn 4xx and 5xx statuses into errors. + match request.send().and_then(|r| r.error_for_status()) { Ok(resp) => match resp.headers().get("content-type") { Some(content_type) => { let content_type = content_type.to_str().map_err(|e| {