diff --git a/mullvad-api/src/rest.rs b/mullvad-api/src/rest.rs index 9d78335234e4..6b8caed9eec5 100644 --- a/mullvad-api/src/rest.rs +++ b/mullvad-api/src/rest.rs @@ -84,6 +84,7 @@ impl From 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 @@ -133,8 +134,10 @@ impl Error { pub(crate) struct RequestService { command_tx: Weak>, client: RequestClient, + command_rx: mpsc::UnboundedReceiver, connector_handle: HttpsConnectorWithSniHandle, client: hyper_util::client::legacy::Client>, + client: RequestClient, connection_mode_provider: T, connection_mode_generation: usize, api_availability: ApiAvailability, @@ -503,8 +506,7 @@ where } pub async fn deserialize(self) -> Result { - let body_length = get_body_length(&self.response); - deserialize_body_inner(self.response, body_length).await + deserialize_body_inner(self.response).await } } @@ -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( @@ -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)) } };