Skip to content

Commit

Permalink
Merge pull request #201 from Orange-OpenSource/feature/improve-error-…
Browse files Browse the repository at this point in the history
…can-not-resolve-host

Specify Host in CouldNotResolveHost Error
  • Loading branch information
fabricereix authored Jun 12, 2021
2 parents 3204970 + 651e823 commit dcc92c6
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion integration/tests/error_http_connection.err
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ error: Http Connection
--> tests/error_http_connection.hurl:1:5
|
1 | GET http://unknown
| ^^^^^^^^^^^^^^ Could not resolve host
| ^^^^^^^^^^^^^^ Could not resolve host <unknown>
|

15 changes: 13 additions & 2 deletions packages/hurl/src/http/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use url::Url;
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum HttpError {
CouldNotResolveProxyName,
CouldNotResolveHost,
CouldNotResolveHost(String),
FailToConnect,
TooManyRedirect,
CouldNotParseResponse,
Expand Down Expand Up @@ -174,7 +174,9 @@ impl Client {
return match e.code() {
3 => Err(HttpError::InvalidUrl),
5 => Err(HttpError::CouldNotResolveProxyName),
6 => Err(HttpError::CouldNotResolveHost),
6 => Err(HttpError::CouldNotResolveHost(extract_host(
request.url.clone(),
))),
7 => Err(HttpError::FailToConnect),
28 => Err(HttpError::Timeout),
60 => Err(HttpError::SslCertificate(
Expand Down Expand Up @@ -565,6 +567,15 @@ impl Header {
}
}

///
/// Extract Hostname for url
/// assume that that the url is a valud url
///
fn extract_host(url: String) -> String {
let url = Url::parse(url.as_str()).expect("valid url");
url.host().expect("valid host").to_string()
}

///
/// Split an array of bytes into http lines (\r\n separator)
///
Expand Down
2 changes: 1 addition & 1 deletion packages/hurl/src/runner/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ pub enum RunnerError {
message: String,
},
CouldNotResolveProxyName,
CouldNotResolveHost,
CouldNotResolveHost(String),
FailToConnect,
Timeout,
TooManyRedirect,
Expand Down
2 changes: 1 addition & 1 deletion packages/hurl/src/runner/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ pub fn run(
Err(http_error) => {
let runner_error = match http_error {
HttpError::CouldNotResolveProxyName => RunnerError::CouldNotResolveProxyName,
HttpError::CouldNotResolveHost => RunnerError::CouldNotResolveHost,
HttpError::CouldNotResolveHost(host) => RunnerError::CouldNotResolveHost(host),
HttpError::FailToConnect => RunnerError::FailToConnect,
HttpError::Timeout => RunnerError::Timeout,
HttpError::TooManyRedirect => RunnerError::TooManyRedirect,
Expand Down
4 changes: 2 additions & 2 deletions packages/hurl/src/runner/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl Error for runner::Error {
RunnerError::VariableNotDefined { .. } => "Undefined Variable".to_string(),
RunnerError::HttpConnection { .. } => "Http Connection".to_string(),
RunnerError::CouldNotResolveProxyName => "Http Connection".to_string(),
RunnerError::CouldNotResolveHost => "Http Connection".to_string(),
RunnerError::CouldNotResolveHost(_) => "Http Connection".to_string(),
RunnerError::FailToConnect => "Http Connection".to_string(),
RunnerError::Timeout => "Http Connection".to_string(),
RunnerError::TooManyRedirect => "Http Connection".to_string(),
Expand Down Expand Up @@ -62,7 +62,7 @@ impl Error for runner::Error {
format!("can not connect to {} ({})", url, message)
}
RunnerError::CouldNotResolveProxyName => "Could not resolve proxy name".to_string(),
RunnerError::CouldNotResolveHost => "Could not resolve host".to_string(),
RunnerError::CouldNotResolveHost(host) => format!("Could not resolve host <{}>", host),
RunnerError::FailToConnect => "Fail to connect".to_string(),
RunnerError::Timeout => "Timeout has been reached".to_string(),
RunnerError::TooManyRedirect => "Too many redirect".to_string(),
Expand Down
2 changes: 1 addition & 1 deletion packages/hurl/tests/libcurl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ fn test_error_could_not_resolve_host() {
let request = default_get_request("http://unknown".to_string());
let error = client.execute(&request, 0).err().unwrap();

assert_eq!(error, HttpError::CouldNotResolveHost);
assert_eq!(error, HttpError::CouldNotResolveHost("unknown".to_string()));
}

#[test]
Expand Down

0 comments on commit dcc92c6

Please sign in to comment.