Skip to content

Commit

Permalink
Add context to error message and update test
Browse files Browse the repository at this point in the history
  • Loading branch information
diehuxx authored and KendallWeihe committed Sep 23, 2024
1 parent feb9760 commit 6fc91ec
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
7 changes: 4 additions & 3 deletions crates/web5/src/credentials/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,9 +572,10 @@ mod tests {
match result {
Err(Web5Error::Network(err_msg)) => {
assert!(
err_msg.contains("failed to lookup address information"),
"Error message is: {}", err_msg
)
err_msg.contains("failed to connect to host"),
"Error message is: {}",
err_msg
)
}
_ => panic!(
"expected Web5Error::Network with specific message but got {:?}",
Expand Down
5 changes: 3 additions & 2 deletions crates/web5/src/credentials/verifiable_credential_1_1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -798,8 +798,9 @@ mod tests {
match result {
Err(Web5Error::Network(err_msg)) => {
assert!(
err_msg.contains("failed to lookup address information"),
"Error message is: {}", err_msg
err_msg.contains("failed to connect to host"),
"Error message is: {}",
err_msg
)
}
_ => panic!(
Expand Down
12 changes: 8 additions & 4 deletions crates/web5/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ fn transmit(destination: &Destination, request: &[u8]) -> Result<Vec<u8>> {
let rc_config = Arc::new(config); // Arc allows sharing the config

// Make the TCP connection to the server
let stream = TcpStream::connect((&destination.host[..], destination.port))
.map_err(|err| Web5Error::Network(err.to_string()))?;
let stream =
TcpStream::connect((&destination.host[..], destination.port)).map_err(|err| {
Web5Error::Network(format!("failed to connect to host: {}", err))
})?;

// Convert the server name to the expected type for TLS validation
let server_name = ServerName::try_from(destination.host.clone())
Expand All @@ -90,8 +92,10 @@ fn transmit(destination: &Destination, request: &[u8]) -> Result<Vec<u8>> {
.map_err(|err| Web5Error::Network(err.to_string()))?;
} else {
// HTTP connection
let mut stream = TcpStream::connect((&destination.host[..], destination.port))
.map_err(|err| Web5Error::Network(err.to_string()))?;
let mut stream =
TcpStream::connect((&destination.host[..], destination.port)).map_err(|err| {
Web5Error::Network(format!("failed to connect to host: {}", err))
})?;

stream
.write_all(request)
Expand Down

0 comments on commit 6fc91ec

Please sign in to comment.