mirror of
https://github.com/nushell/nushell.git
synced 2024-11-22 08:23:24 +01:00
Convert ShellError::NetworkFailure to named fields (#11093)
# Description Part of #10700
This commit is contained in:
parent
08715e6308
commit
da59dfe7d2
@ -363,38 +363,26 @@ pub fn request_add_custom_headers(
|
|||||||
|
|
||||||
fn handle_response_error(span: Span, requested_url: &str, response_err: Error) -> ShellError {
|
fn handle_response_error(span: Span, requested_url: &str, response_err: Error) -> ShellError {
|
||||||
match response_err {
|
match response_err {
|
||||||
Error::Status(301, _) => ShellError::NetworkFailure(
|
Error::Status(301, _) => ShellError::NetworkFailure { msg: format!("Resource moved permanently (301): {requested_url:?}"), span },
|
||||||
format!("Resource moved permanently (301): {requested_url:?}"),
|
|
||||||
span,
|
|
||||||
),
|
|
||||||
Error::Status(400, _) => {
|
Error::Status(400, _) => {
|
||||||
ShellError::NetworkFailure(format!("Bad request (400) to {requested_url:?}"), span)
|
ShellError::NetworkFailure { msg: format!("Bad request (400) to {requested_url:?}"), span }
|
||||||
}
|
}
|
||||||
Error::Status(403, _) => {
|
Error::Status(403, _) => {
|
||||||
ShellError::NetworkFailure(format!("Access forbidden (403) to {requested_url:?}"), span)
|
ShellError::NetworkFailure { msg: format!("Access forbidden (403) to {requested_url:?}"), span }
|
||||||
}
|
}
|
||||||
Error::Status(404, _) => ShellError::NetworkFailure(
|
Error::Status(404, _) => ShellError::NetworkFailure { msg: format!("Requested file not found (404): {requested_url:?}"), span },
|
||||||
format!("Requested file not found (404): {requested_url:?}"),
|
|
||||||
span,
|
|
||||||
),
|
|
||||||
Error::Status(408, _) => {
|
Error::Status(408, _) => {
|
||||||
ShellError::NetworkFailure(format!("Request timeout (408): {requested_url:?}"), span)
|
ShellError::NetworkFailure { msg: format!("Request timeout (408): {requested_url:?}"), span }
|
||||||
}
|
}
|
||||||
Error::Status(_, _) => ShellError::NetworkFailure(
|
Error::Status(_, _) => ShellError::NetworkFailure { msg: format!(
|
||||||
format!(
|
|
||||||
"Cannot make request to {:?}. Error is {:?}",
|
"Cannot make request to {:?}. Error is {:?}",
|
||||||
requested_url,
|
requested_url,
|
||||||
response_err.to_string()
|
response_err.to_string()
|
||||||
),
|
), span },
|
||||||
span,
|
|
||||||
),
|
|
||||||
|
|
||||||
Error::Transport(t) => match t {
|
Error::Transport(t) => match t {
|
||||||
t if t.kind() == ErrorKind::ConnectionFailed => ShellError::NetworkFailure(
|
t if t.kind() == ErrorKind::ConnectionFailed => ShellError::NetworkFailure { msg: format!("Cannot make request to {requested_url}, there was an error establishing a connection.",), span },
|
||||||
format!("Cannot make request to {requested_url}, there was an error establishing a connection.",),
|
t => ShellError::NetworkFailure { msg: t.to_string(), span },
|
||||||
span,
|
|
||||||
),
|
|
||||||
t => ShellError::NetworkFailure(t.to_string(), span),
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -676,7 +676,11 @@ pub enum ShellError {
|
|||||||
/// It's always DNS.
|
/// It's always DNS.
|
||||||
#[error("Network failure")]
|
#[error("Network failure")]
|
||||||
#[diagnostic(code(nu::shell::network_failure))]
|
#[diagnostic(code(nu::shell::network_failure))]
|
||||||
NetworkFailure(String, #[label("{0}")] Span),
|
NetworkFailure {
|
||||||
|
msg: String,
|
||||||
|
#[label("{msg}")]
|
||||||
|
span: Span,
|
||||||
|
},
|
||||||
|
|
||||||
/// Help text for this command could not be found.
|
/// Help text for this command could not be found.
|
||||||
///
|
///
|
||||||
|
Loading…
Reference in New Issue
Block a user