Skip to content

Commit

Permalink
feat(rad): implement RadError::{InvalidHttpBody, InvalidHttpResponse}
Browse files Browse the repository at this point in the history
  • Loading branch information
guidiaz committed Jan 24, 2024
1 parent 13225c8 commit a8d0b57
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions rad/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,22 +266,21 @@ async fn http_response(
for (name, value) in &retrieve.headers {
// Handle invalid header names and values with a specific and friendly error message
validate_header(name, value)?;

builder = builder.header(name, value);
}

// Finally attach the body to complete building the HTTP request
builder.body(body).map_err(|e| RadError::HttpOther {
message: e.to_string(),
builder.body(body).map_err(|e| RadError::InvalidHttpBody {
error: e.to_string(),
})
})?;

let start_ts = std::time::SystemTime::now();
let response = client
.send(request)
.await
.map_err(|x| RadError::HttpOther {
message: x.to_string(),
.map_err(|err| RadError::InvalidHttpResponse {
error: err.to_string()
})?
.inner();

Expand All @@ -301,8 +300,8 @@ async fn http_response(
// todo: before reading the response buffer, an error should be thrown if it was too big
body.read_to_end(&mut response_bytes)
.await
.map_err(|x| RadError::HttpOther {
message: x.to_string(),
.map_err(|x| RadError::InvalidHttpResponse {
error: x.to_string(),
})?;
response = RadonTypes::from(RadonBytes::from(response_bytes));
} else {
Expand All @@ -315,8 +314,8 @@ async fn http_response(
_ => {
body.read_to_string(&mut response_string)
.await
.map_err(|x| RadError::HttpOther {
message: x.to_string(),
.map_err(|x| RadError::InvalidHttpResponse {
error: x.to_string(),
})?;
}
}
Expand Down

0 comments on commit a8d0b57

Please sign in to comment.