Skip to content

Commit

Permalink
fix: Use if_exists for delete basin/stream (#85)
Browse files Browse the repository at this point in the history
This probably got removed when we shifted to using simply `Status` for
errors which removed `parse_status`.

Resolves: #83

Signed-off-by: Vaibhav Rabber <[email protected]>
  • Loading branch information
vrongmeal authored Nov 27, 2024
1 parent 35cf031 commit 2b5ef21
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/service/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,12 @@ impl ServiceRequest for DeleteBasinServiceRequest {
&mut self,
req: tonic::Request<Self::ApiRequest>,
) -> Result<tonic::Response<Self::ApiResponse>, tonic::Status> {
self.client.delete_basin(req).await
match self.client.delete_basin(req).await {
Err(status) if self.req.if_exists && status.code() == tonic::Code::NotFound => {
Ok(tonic::Response::new(api::DeleteBasinResponse {}))
}
other => other,
}
}

fn parse_response(
Expand Down
7 changes: 6 additions & 1 deletion src/service/basin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,12 @@ impl ServiceRequest for DeleteStreamServiceRequest {
&mut self,
req: tonic::Request<Self::ApiRequest>,
) -> Result<tonic::Response<Self::ApiResponse>, tonic::Status> {
self.client.delete_stream(req).await
match self.client.delete_stream(req).await {
Err(status) if self.req.if_exists && status.code() == tonic::Code::NotFound => {
Ok(tonic::Response::new(api::DeleteStreamResponse {}))
}
other => other,
}
}

fn parse_response(
Expand Down
2 changes: 2 additions & 0 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,7 @@ impl TryFrom<api::ListBasinsResponse> for ListBasinsResponse {
#[derive(Debug, Clone)]
pub struct DeleteBasinRequest {
pub basin: BasinName,
/// Delete basin if it exists else do nothing.
pub if_exists: bool,
}

Expand Down Expand Up @@ -634,6 +635,7 @@ impl From<DeleteBasinRequest> for api::DeleteBasinRequest {
#[derive(Debug, Clone)]
pub struct DeleteStreamRequest {
pub stream: String,
/// Delete stream if it exists else do nothing.
pub if_exists: bool,
}

Expand Down

0 comments on commit 2b5ef21

Please sign in to comment.