Skip to content

Commit 0c33684

Browse files
authored
Properly handle IO-related HTTP errors (#705)
These should mostly just emit the IO error’s underlying message, so we do that for all IO errors that don’t have a specific override
1 parent 40c92e9 commit 0c33684

File tree

2 files changed

+5
-18
lines changed

2 files changed

+5
-18
lines changed

wp_api/src/reqwest_request_executor.rs

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -187,35 +187,22 @@ impl From<reqwest::Error> for RequestExecutionError {
187187

188188
if let Some(io_error) = error.as_io_error() {
189189
match io_error.kind() {
190-
std::io::ErrorKind::ConnectionRefused => {
191-
return RequestExecutionError::RequestExecutionFailed {
192-
status_code,
193-
redirects: None,
194-
reason: RequestExecutionErrorReason::NonExistentSiteError {
195-
error_message: Some("Connection refused".to_string()),
196-
suggested_action: None,
197-
},
198-
};
199-
}
200190
std::io::ErrorKind::UnexpectedEof => {
201191
// Server terminated the connection unexpectedly
202192
return RequestExecutionError::RequestExecutionFailed {
203193
status_code,
204194
redirects: None,
205-
reason: RequestExecutionErrorReason::NonExistentSiteError {
206-
error_message: Some(
207-
"The server terminated the connection unexpectedly".to_string(),
208-
),
209-
suggested_action: None,
195+
reason: RequestExecutionErrorReason::HttpError {
196+
reason: "The server terminated the connection unexpectedly".to_string(),
210197
},
211198
};
212199
}
213200
_ => {
214201
return RequestExecutionError::RequestExecutionFailed {
215202
status_code,
216203
redirects: None,
217-
reason: RequestExecutionErrorReason::GenericError {
218-
error_message: error.to_string(),
204+
reason: RequestExecutionErrorReason::HttpError {
205+
reason: io_error.to_string(),
219206
},
220207
};
221208
}

wp_rs_cli/src/bin/wp_rs_cli/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ impl SimplifiedDiscoveryResult {
182182
println!("{}", format!("Login URL found: {login_url}").green());
183183
}
184184
Err(error) => {
185-
println!("{}", format!("Error: {}", error).red());
185+
println!("{}", error.to_string().red());
186186
}
187187
}
188188
}

0 commit comments

Comments
 (0)