Skip to content

Commit

Permalink
SM-874: Revert error.rs, projects/delete.rs, and secrets/delete.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
coltonhurst committed Oct 23, 2023
1 parent b489e6d commit 171d8a3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 60 deletions.
4 changes: 0 additions & 4 deletions crates/bitwarden/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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),
}
Expand Down
40 changes: 12 additions & 28 deletions crates/bitwarden/src/secrets_manager/projects/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,14 @@ impl ProjectsDeleteResponse {
pub(crate) fn process_response(
response: BulkDeleteResponseModelListResponseModel,
) -> Result<ProjectsDeleteResponse> {
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::<Result<_, _>>()?,
})
}
}

Expand All @@ -75,11 +61,9 @@ impl ProjectDeleteResponse {
pub(crate) fn process_response(
response: BulkDeleteResponseModel,
) -> Result<ProjectDeleteResponse> {
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,
})
}
}
40 changes: 12 additions & 28 deletions crates/bitwarden/src/secrets_manager/secrets/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,14 @@ impl SecretsDeleteResponse {
pub(crate) fn process_response(
response: BulkDeleteResponseModelListResponseModel,
) -> Result<SecretsDeleteResponse> {
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::<Result<_, _>>()?,
})
}
}

Expand All @@ -75,11 +61,9 @@ impl SecretDeleteResponse {
pub(crate) fn process_response(
response: BulkDeleteResponseModel,
) -> Result<SecretDeleteResponse> {
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,
})
}
}

0 comments on commit 171d8a3

Please sign in to comment.