diff options
author | Alex <alex@adnab.me> | 2020-11-08 18:04:52 +0100 |
---|---|---|
committer | Alex <alex@adnab.me> | 2020-11-08 18:04:52 +0100 |
commit | 045009da9b7ac4198574bd5aa256c11cfe4ae469 (patch) | |
tree | d3014cc2739c5a1bce62ff35efc8417b79ff46ef /src/garage | |
parent | 54166d2a09f488bff080469160d4df6a78db1a3f (diff) | |
parent | a50fa70d45f8b5af68d23d60c3bac2af4ecceb58 (diff) | |
download | garage-045009da9b7ac4198574bd5aa256c11cfe4ae469.tar.gz garage-045009da9b7ac4198574bd5aa256c11cfe4ae469.zip |
Merge pull request 'Refactor error management in API part' (#10) from error-refactoring into master
Reviewed-on: https://git.deuxfleurs.fr/Deuxfleurs/garage/pulls/10
Diffstat (limited to 'src/garage')
-rw-r--r-- | src/garage/admin_rpc.rs | 19 |
1 files changed, 8 insertions, 11 deletions
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<Self>, opt: RepairOpt) -> Result<AdminRPC, Error> { if !opt.yes { - return Err(Error::BadRequest(format!( + return Err(Error::BadRPC(format!( "Please provide the --yes flag to initiate repair operations." ))); } |