Skip to content

Commit

Permalink
fixup! Replace old client with hyper_util legacy client
Browse files Browse the repository at this point in the history
  • Loading branch information
Serock3 committed Oct 14, 2024
1 parent e8289f7 commit 7bd7aa7
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions mullvad-api/src/rest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ impl From<Infallible> for Error {
impl Error {
pub fn is_network_error(&self) -> bool {
matches!(self, Error::HyperError(_) | Error::TimeoutError)
)
}

/// Return true if there was no route to the destination
Expand Down Expand Up @@ -133,8 +134,10 @@ impl Error {
pub(crate) struct RequestService<T: ConnectionModeProvider> {
command_tx: Weak<mpsc::UnboundedSender<RequestCommand>>,
client: RequestClient,
command_rx: mpsc::UnboundedReceiver<RequestCommand>,
connector_handle: HttpsConnectorWithSniHandle,
client: hyper_util::client::legacy::Client<HttpsConnectorWithSni, BoxBody<Bytes, Error>>,
client: RequestClient,
connection_mode_provider: T,
connection_mode_generation: usize,
api_availability: ApiAvailability,
Expand Down Expand Up @@ -503,8 +506,7 @@ where
}

pub async fn deserialize<T: serde::de::DeserializeOwned>(self) -> Result<T> {
let body_length = get_body_length(&self.response);
deserialize_body_inner(self.response, body_length).await
deserialize_body_inner(self.response).await
}
}

Expand Down Expand Up @@ -648,14 +650,13 @@ where
hyper::StatusCode::METHOD_NOT_ALLOWED => "Method not allowed",
status => match get_body_length(&response) {
0 => status.canonical_reason().unwrap_or("Unexpected error"),
body_length => {
_length => {
return match response.headers().get("content-type") {
Some(content_type) if content_type == "application/problem+json" => {
// TODO: We should make sure we unify the new error format and the old
// error format so that they both produce the same Errors for the same
// problems after being processed.
let err: NewErrorResponse =
deserialize_body_inner(response, body_length).await?;
let err: NewErrorResponse = deserialize_body_inner(response).await?;
// The new error type replaces the `code` field with the `type` field.
// This is what is used to programmatically check the error.
Err(Error::ApiError(
Expand All @@ -665,8 +666,7 @@ where
))
}
_ => {
let err: OldErrorResponse =
deserialize_body_inner(response, body_length).await?;
let err: OldErrorResponse = deserialize_body_inner(response).await?;
Err(Error::ApiError(status, err.code))
}
};
Expand Down

0 comments on commit 7bd7aa7

Please sign in to comment.