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 committed Sep 17, 2024
1 parent b0d082e commit 7796874
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion crates/web5/src/credentials/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ mod tests {
match result {
Err(Web5Error::Network(err_msg)) => {
assert!(
err_msg.contains("failed to lookup address information"),
err_msg.contains("failed to connect to host"),
"Error message is: {}", err_msg
)
}
Expand Down
2 changes: 1 addition & 1 deletion crates/web5/src/credentials/verifiable_credential_1_1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ mod tests {
match result {
Err(Web5Error::Network(err_msg)) => {
assert!(
err_msg.contains("failed to lookup address information"),
err_msg.contains("failed to connect to host"),
"Error message is: {}", err_msg
)
}
Expand Down
8 changes: 6 additions & 2 deletions crates/web5/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ fn transmit(destination: &Destination, request: &[u8]) -> Result<Vec<u8>> {

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

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

stream
.write_all(request)
Expand Down

0 comments on commit 7796874

Please sign in to comment.