mirror of
https://github.com/Orange-OpenSource/hurl.git
synced 2024-12-28 05:23:56 +03:00
Merge pull request #27 from Orange-OpenSource/feature/http-errors
Improve http error messages
This commit is contained in:
commit
03527bd372
@ -2,6 +2,6 @@ error: Http Connection
|
|||||||
--> tests/error_http_connection.hurl:1:5
|
--> tests/error_http_connection.hurl:1:5
|
||||||
|
|
|
|
||||||
1 | GET http://unknown
|
1 | GET http://unknown
|
||||||
| ^^^^^^^^^^^^^^ can not connect to http://unknown/ ("http://unknown/: error trying to connect: failed to lookup address information: Name or service not known")
|
| ^^^^^^^^^^^^^^ Could not resolve host
|
||||||
|
|
|
|
||||||
|
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
2
|
3
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
error: Http Connection
|
error: Invalid url
|
||||||
--> tests/error_invalid_url.hurl:1:5
|
--> tests/error_invalid_url.hurl:1:5
|
||||||
|
|
|
|
||||||
1 | GET unknown
|
1 | GET ???
|
||||||
| ^^^^^^^ can not connect to unknown
|
| ^^^ Invalid url <???>
|
||||||
|
|
|
|
||||||
|
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
GET unknown
|
GET ???
|
||||||
|
|
||||||
|
@ -35,6 +35,8 @@ pub enum HttpError {
|
|||||||
TooManyRedirect,
|
TooManyRedirect,
|
||||||
CouldNotParseResponse,
|
CouldNotParseResponse,
|
||||||
SSLCertificate,
|
SSLCertificate,
|
||||||
|
InvalidUrl,
|
||||||
|
Other { description: String, code: u32 },
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -170,13 +172,17 @@ impl Client {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
if let Err(e) = transfer.perform() {
|
if let Err(e) = transfer.perform() {
|
||||||
match e.code() {
|
return match e.code() {
|
||||||
5 => return Err(HttpError::CouldNotResolveProxyName),
|
3 => Err(HttpError::InvalidUrl),
|
||||||
6 => return Err(HttpError::CouldNotResolveHost),
|
5 => Err(HttpError::CouldNotResolveProxyName),
|
||||||
7 => return Err(HttpError::FailToConnect),
|
6 => Err(HttpError::CouldNotResolveHost),
|
||||||
60 => return Err(HttpError::SSLCertificate),
|
7 => Err(HttpError::FailToConnect),
|
||||||
_ => panic!("{:#?}", e),
|
60 => Err(HttpError::SSLCertificate),
|
||||||
}
|
_ => Err(HttpError::Other {
|
||||||
|
code: e.code(),
|
||||||
|
description: e.description().to_string(),
|
||||||
|
}),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,10 +114,18 @@ pub enum RunnerError {
|
|||||||
name: String,
|
name: String,
|
||||||
},
|
},
|
||||||
InvalidURL(String),
|
InvalidURL(String),
|
||||||
|
|
||||||
HttpConnection {
|
HttpConnection {
|
||||||
url: String,
|
url: String,
|
||||||
message: String,
|
message: String,
|
||||||
},
|
},
|
||||||
|
CouldNotResolveProxyName,
|
||||||
|
CouldNotResolveHost,
|
||||||
|
FailToConnect,
|
||||||
|
TooManyRedirect,
|
||||||
|
CouldNotParseResponse,
|
||||||
|
SSLCertificate,
|
||||||
|
|
||||||
FileReadAccess {
|
FileReadAccess {
|
||||||
value: String,
|
value: String,
|
||||||
},
|
},
|
||||||
@ -181,6 +189,12 @@ impl FormatError for Error {
|
|||||||
RunnerError::TemplateVariableNotDefined { .. } => "Undefined Variable".to_string(),
|
RunnerError::TemplateVariableNotDefined { .. } => "Undefined Variable".to_string(),
|
||||||
RunnerError::VariableNotDefined { .. } => "Undefined Variable".to_string(),
|
RunnerError::VariableNotDefined { .. } => "Undefined Variable".to_string(),
|
||||||
RunnerError::HttpConnection { .. } => "Http Connection".to_string(),
|
RunnerError::HttpConnection { .. } => "Http Connection".to_string(),
|
||||||
|
RunnerError::CouldNotResolveProxyName => "Http Connection".to_string(),
|
||||||
|
RunnerError::CouldNotResolveHost => "Http Connection".to_string(),
|
||||||
|
RunnerError::FailToConnect => "Http Connection".to_string(),
|
||||||
|
RunnerError::TooManyRedirect => "Http Connection".to_string(),
|
||||||
|
RunnerError::CouldNotParseResponse => "Http Connection".to_string(),
|
||||||
|
RunnerError::SSLCertificate => "Http Connection".to_string(),
|
||||||
RunnerError::PredicateValue { .. } => "Assert - Predicate Value Failed".to_string(),
|
RunnerError::PredicateValue { .. } => "Assert - Predicate Value Failed".to_string(),
|
||||||
RunnerError::InvalidRegex {} => "Invalid regex".to_string(),
|
RunnerError::InvalidRegex {} => "Invalid regex".to_string(),
|
||||||
RunnerError::FileReadAccess { .. } => "File ReadAccess".to_string(),
|
RunnerError::FileReadAccess { .. } => "File ReadAccess".to_string(),
|
||||||
@ -210,7 +224,15 @@ impl FormatError for Error {
|
|||||||
RunnerError::TemplateVariableNotDefined { name } => {
|
RunnerError::TemplateVariableNotDefined { name } => {
|
||||||
format!("You must set the variable {}", name)
|
format!("You must set the variable {}", name)
|
||||||
}
|
}
|
||||||
RunnerError::HttpConnection { url, .. } => format!("can not connect to {}", url),
|
RunnerError::HttpConnection { url, message } => {
|
||||||
|
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::FailToConnect => "Fail to connect".to_string(),
|
||||||
|
RunnerError::TooManyRedirect => "Too many redirect".to_string(),
|
||||||
|
RunnerError::CouldNotParseResponse => "Could not parse response".to_string(),
|
||||||
|
RunnerError::SSLCertificate => "SSl Certificate".to_string(),
|
||||||
RunnerError::AssertVersion { actual, .. } => format!("actual value is <{}>", actual),
|
RunnerError::AssertVersion { actual, .. } => format!("actual value is <{}>", actual),
|
||||||
RunnerError::AssertStatus { actual, .. } => format!("actual value is <{}>", actual),
|
RunnerError::AssertStatus { actual, .. } => format!("actual value is <{}>", actual),
|
||||||
RunnerError::PredicateValue(value) => {
|
RunnerError::PredicateValue(value) => {
|
||||||
|
@ -26,6 +26,7 @@ use crate::http;
|
|||||||
use super::core::*;
|
use super::core::*;
|
||||||
use super::core::{Error, RunnerError};
|
use super::core::{Error, RunnerError};
|
||||||
use crate::format::logger::Logger;
|
use crate::format::logger::Logger;
|
||||||
|
use crate::http::HttpError;
|
||||||
|
|
||||||
/// Run an entry with the hurl http client
|
/// Run an entry with the hurl http client
|
||||||
///
|
///
|
||||||
@ -103,7 +104,20 @@ pub fn run(
|
|||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
let http_response = match http_client.execute(&http_request, 0) {
|
let http_response = match http_client.execute(&http_request, 0) {
|
||||||
Ok(response) => response,
|
Ok(response) => response,
|
||||||
Err(_) => {
|
Err(http_error) => {
|
||||||
|
let runner_error = match http_error {
|
||||||
|
HttpError::CouldNotResolveProxyName => RunnerError::CouldNotResolveProxyName,
|
||||||
|
HttpError::CouldNotResolveHost => RunnerError::CouldNotResolveHost,
|
||||||
|
HttpError::FailToConnect => RunnerError::FailToConnect,
|
||||||
|
HttpError::TooManyRedirect => RunnerError::TooManyRedirect,
|
||||||
|
HttpError::CouldNotParseResponse => RunnerError::CouldNotParseResponse,
|
||||||
|
HttpError::SSLCertificate => RunnerError::SSLCertificate,
|
||||||
|
HttpError::InvalidUrl => RunnerError::InvalidURL(http_request.url.clone()),
|
||||||
|
HttpError::Other { description, .. } => RunnerError::HttpConnection {
|
||||||
|
message: description,
|
||||||
|
url: http_request.url.clone(),
|
||||||
|
},
|
||||||
|
};
|
||||||
return EntryResult {
|
return EntryResult {
|
||||||
request: Some(http_request.clone()),
|
request: Some(http_request.clone()),
|
||||||
response: None,
|
response: None,
|
||||||
@ -114,10 +128,7 @@ pub fn run(
|
|||||||
start: entry.clone().request.url.source_info.start,
|
start: entry.clone().request.url.source_info.start,
|
||||||
end: entry.clone().request.url.source_info.end,
|
end: entry.clone().request.url.source_info.end,
|
||||||
},
|
},
|
||||||
inner: RunnerError::HttpConnection {
|
inner: runner_error,
|
||||||
message: "".to_string(),
|
|
||||||
url: http_request.url,
|
|
||||||
},
|
|
||||||
assert: false,
|
assert: false,
|
||||||
}],
|
}],
|
||||||
time_in_ms: 0,
|
time_in_ms: 0,
|
||||||
|
Loading…
Reference in New Issue
Block a user