From 171d8a3a8f4c0515fc4962764c4a52b8ca65ed8d Mon Sep 17 00:00:00 2001 From: Colton Hurst Date: Mon, 23 Oct 2023 08:30:20 -0400 Subject: [PATCH] SM-874: Revert error.rs, projects/delete.rs, and secrets/delete.rs --- crates/bitwarden/src/error.rs | 4 -- .../src/secrets_manager/projects/delete.rs | 40 ++++++------------- .../src/secrets_manager/secrets/delete.rs | 40 ++++++------------- 3 files changed, 24 insertions(+), 60 deletions(-) diff --git a/crates/bitwarden/src/error.rs b/crates/bitwarden/src/error.rs index fcbdb208a..6a9b0d8aa 100644 --- a/crates/bitwarden/src/error.rs +++ b/crates/bitwarden/src/error.rs @@ -6,7 +6,6 @@ use bitwarden_api_api::apis::Error as ApiError; use bitwarden_api_identity::apis::Error as IdentityError; use reqwest::StatusCode; use thiserror::Error; -use uuid::Uuid; #[derive(Debug, Error)] pub enum Error { @@ -47,9 +46,6 @@ pub enum Error { #[error("Received error message from server: [{}] {}", .status, .message)] ResponseContent { status: StatusCode, message: String }, - #[error("Received error messages from the API: {0:?}")] - ApiError(Vec<(Uuid, String)>), - #[error("Internal error: {0}")] Internal(&'static str), } diff --git a/crates/bitwarden/src/secrets_manager/projects/delete.rs b/crates/bitwarden/src/secrets_manager/projects/delete.rs index fcdb74697..55f792669 100644 --- a/crates/bitwarden/src/secrets_manager/projects/delete.rs +++ b/crates/bitwarden/src/secrets_manager/projects/delete.rs @@ -39,28 +39,14 @@ impl ProjectsDeleteResponse { pub(crate) fn process_response( response: BulkDeleteResponseModelListResponseModel, ) -> Result { - let mut successes = Vec::new(); - let mut failures = Vec::new(); - - for item in response.data.unwrap_or_default() { - match ProjectDeleteResponse::process_response(item) { - Ok(data) => { - successes.push(data); - } - Err(Error::ApiError(error)) => { - failures.extend_from_slice(&error); - } - Err(_) => { - unreachable!(); - } - } - } - - if failures.is_empty() { - Ok(ProjectsDeleteResponse { data: successes }) - } else { - Err(Error::ApiError(failures)) - } + Ok(ProjectsDeleteResponse { + data: response + .data + .unwrap_or_default() + .into_iter() + .map(ProjectDeleteResponse::process_response) + .collect::>()?, + }) } } @@ -75,11 +61,9 @@ impl ProjectDeleteResponse { pub(crate) fn process_response( response: BulkDeleteResponseModel, ) -> Result { - let id = response.id.ok_or(Error::MissingFields)?; - - match response.error { - Some(error) => Err(Error::ApiError(vec![(id, error)])), - None => Ok(ProjectDeleteResponse { id, error: None }), - } + Ok(ProjectDeleteResponse { + id: response.id.ok_or(Error::MissingFields)?, + error: response.error, + }) } } diff --git a/crates/bitwarden/src/secrets_manager/secrets/delete.rs b/crates/bitwarden/src/secrets_manager/secrets/delete.rs index 3cc46cbcd..19337e7a1 100644 --- a/crates/bitwarden/src/secrets_manager/secrets/delete.rs +++ b/crates/bitwarden/src/secrets_manager/secrets/delete.rs @@ -39,28 +39,14 @@ impl SecretsDeleteResponse { pub(crate) fn process_response( response: BulkDeleteResponseModelListResponseModel, ) -> Result { - let mut successes = Vec::new(); - let mut failures = Vec::new(); - - for item in response.data.unwrap_or_default() { - match SecretDeleteResponse::process_response(item) { - Ok(data) => { - successes.push(data); - } - Err(Error::ApiError(error)) => { - failures.extend_from_slice(&error); - } - Err(_) => { - unreachable!(); - } - } - } - - if failures.is_empty() { - Ok(SecretsDeleteResponse { data: successes }) - } else { - Err(Error::ApiError(failures)) - } + Ok(SecretsDeleteResponse { + data: response + .data + .unwrap_or_default() + .into_iter() + .map(SecretDeleteResponse::process_response) + .collect::>()?, + }) } } @@ -75,11 +61,9 @@ impl SecretDeleteResponse { pub(crate) fn process_response( response: BulkDeleteResponseModel, ) -> Result { - let id = response.id.ok_or(Error::MissingFields)?; - - match response.error { - Some(error) => Err(Error::ApiError(vec![(id, error)])), - None => Ok(SecretDeleteResponse { id, error: None }), - } + Ok(SecretDeleteResponse { + id: response.id.ok_or(Error::MissingFields)?, + error: response.error, + }) } }