diff --git a/crates/bitwarden/src/error.rs b/crates/bitwarden/src/error.rs index 6a9b0d8aa..fcbdb208a 100644 --- a/crates/bitwarden/src/error.rs +++ b/crates/bitwarden/src/error.rs @@ -6,6 +6,7 @@ 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 { @@ -46,6 +47,9 @@ 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/secrets/delete.rs b/crates/bitwarden/src/secrets_manager/secrets/delete.rs index 19337e7a1..01c7e47ee 100644 --- a/crates/bitwarden/src/secrets_manager/secrets/delete.rs +++ b/crates/bitwarden/src/secrets_manager/secrets/delete.rs @@ -39,14 +39,28 @@ impl SecretsDeleteResponse { pub(crate) fn process_response( response: BulkDeleteResponseModelListResponseModel, ) -> Result { - Ok(SecretsDeleteResponse { - data: response - .data - .unwrap_or_default() - .into_iter() - .map(SecretDeleteResponse::process_response) - .collect::>()?, - }) + 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)) + } } } @@ -61,9 +75,14 @@ impl SecretDeleteResponse { pub(crate) fn process_response( response: BulkDeleteResponseModel, ) -> Result { - Ok(SecretDeleteResponse { - id: response.id.ok_or(Error::MissingFields)?, - error: response.error, - }) + let id = response.id.ok_or(Error::MissingFields)?; + + match response.error { + Some(error) => Err(Error::ApiError(vec![(id, error)])), + None => Ok(SecretDeleteResponse { + id: id, + error: None, + }), + } } }