From a50fa70d45f8b5af68d23d60c3bac2af4ecceb58 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Sun, 8 Nov 2020 15:04:30 +0100 Subject: Refactor error management in API part --- src/garage/admin_rpc.rs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'src/garage/admin_rpc.rs') diff --git a/src/garage/admin_rpc.rs b/src/garage/admin_rpc.rs index 1dd118ac..b29f2f77 100644 --- a/src/garage/admin_rpc.rs +++ b/src/garage/admin_rpc.rs @@ -55,7 +55,7 @@ impl AdminRpcHandler { AdminRPC::BucketOperation(bo) => self2.handle_bucket_cmd(bo).await, AdminRPC::KeyOperation(ko) => self2.handle_key_cmd(ko).await, AdminRPC::LaunchRepair(opt) => self2.handle_launch_repair(opt).await, - _ => Err(Error::BadRequest(format!("Invalid RPC"))), + _ => Err(Error::BadRPC(format!("Invalid RPC"))), } } }); @@ -81,7 +81,7 @@ impl AdminRpcHandler { BucketOperation::Create(query) => { let bucket = self.garage.bucket_table.get(&EmptyKey, &query.name).await?; if bucket.as_ref().filter(|b| !b.deleted).is_some() { - return Err(Error::BadRequest(format!( + return Err(Error::BadRPC(format!( "Bucket {} already exists", query.name ))); @@ -104,13 +104,10 @@ impl AdminRpcHandler { .get_range(&query.name, None, Some(()), 10) .await?; if !objects.is_empty() { - return Err(Error::BadRequest(format!( - "Bucket {} is not empty", - query.name - ))); + return Err(Error::BadRPC(format!("Bucket {} is not empty", query.name))); } if !query.yes { - return Err(Error::BadRequest(format!( + return Err(Error::BadRPC(format!( "Add --yes flag to really perform this operation" ))); } @@ -199,7 +196,7 @@ impl AdminRpcHandler { KeyOperation::Delete(query) => { let key = self.get_existing_key(&query.key_id).await?; if !query.yes { - return Err(Error::BadRequest(format!( + return Err(Error::BadRPC(format!( "Add --yes flag to really perform this operation" ))); } @@ -233,7 +230,7 @@ impl AdminRpcHandler { .await? .filter(|b| !b.deleted) .map(Ok) - .unwrap_or(Err(Error::BadRequest(format!( + .unwrap_or(Err(Error::BadRPC(format!( "Bucket {} does not exist", bucket )))) @@ -246,7 +243,7 @@ impl AdminRpcHandler { .await? .filter(|k| !k.deleted) .map(Ok) - .unwrap_or(Err(Error::BadRequest(format!("Key {} does not exist", id)))) + .unwrap_or(Err(Error::BadRPC(format!("Key {} does not exist", id)))) } async fn update_bucket_key( @@ -306,7 +303,7 @@ impl AdminRpcHandler { async fn handle_launch_repair(self: &Arc, opt: RepairOpt) -> Result { if !opt.yes { - return Err(Error::BadRequest(format!( + return Err(Error::BadRPC(format!( "Please provide the --yes flag to initiate repair operations." ))); } -- cgit v1.2.3