aboutsummaryrefslogtreecommitdiff
path: root/src/api/s3_put.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2022-01-05 17:07:36 +0100
committerAlex Auvolat <alex@adnab.me>2022-01-05 17:07:36 +0100
commit168a90dfb5489d465d64f066f375e5d06bc1f08c (patch)
tree7fd1430cb52cf77a654ba93324b40c05d936f5a8 /src/api/s3_put.rs
parentfb1e31add06ee3739fc95099aa5ffe96cf011e9c (diff)
downloadgarage-168a90dfb5489d465d64f066f375e5d06bc1f08c.tar.gz
garage-168a90dfb5489d465d64f066f375e5d06bc1f08c.zip
Fix some error codes
Diffstat (limited to 'src/api/s3_put.rs')
-rw-r--r--src/api/s3_put.rs16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/api/s3_put.rs b/src/api/s3_put.rs
index 152e59b4..bb92c252 100644
--- a/src/api/s3_put.rs
+++ b/src/api/s3_put.rs
@@ -382,7 +382,7 @@ pub async fn handle_put_part(
.iter()
.any(|v| v.uuid == version_uuid && v.is_uploading())
{
- return Err(Error::NotFound);
+ return Err(Error::NoSuchUpload);
}
// Copy block to store
@@ -449,15 +449,15 @@ pub async fn handle_complete_multipart_upload(
garage.version_table.get(&version_uuid, &EmptyKey),
)?;
- let object = object.ok_or_else(|| Error::BadRequest("Object not found".to_string()))?;
+ let object = object.ok_or(Error::NoSuchKey)?;
let mut object_version = object
.versions()
.iter()
.find(|v| v.uuid == version_uuid && v.is_uploading())
.cloned()
- .ok_or_else(|| Error::BadRequest("Version not found".to_string()))?;
+ .ok_or(Error::NoSuchUpload)?;
- let version = version.ok_or_else(|| Error::BadRequest("Version not found".to_string()))?;
+ let version = version.ok_or(Error::NoSuchKey)?;
if version.blocks.is_empty() {
return Err(Error::BadRequest("No data was uploaded".to_string()));
}
@@ -538,14 +538,14 @@ pub async fn handle_abort_multipart_upload(
.object_table
.get(&bucket_id, &key.to_string())
.await?;
- let object = object.ok_or_else(|| Error::BadRequest("Object not found".to_string()))?;
+ let object = object.ok_or(Error::NoSuchKey)?;
let object_version = object
.versions()
.iter()
.find(|v| v.uuid == version_uuid && v.is_uploading());
let mut object_version = match object_version {
- None => return Err(Error::NotFound),
+ None => return Err(Error::NoSuchUpload),
Some(x) => x.clone(),
};
@@ -611,9 +611,9 @@ pub(crate) fn get_headers(req: &Request<Body>) -> Result<ObjectVersionHeaders, E
}
fn decode_upload_id(id: &str) -> Result<Uuid, Error> {
- let id_bin = hex::decode(id).ok_or_bad_request("Invalid upload ID")?;
+ let id_bin = hex::decode(id).map_err(|_| Error::NoSuchUpload)?;
if id_bin.len() != 32 {
- return None.ok_or_bad_request("Invalid upload ID");
+ return Err(Error::NoSuchUpload);
}
let mut uuid = [0u8; 32];
uuid.copy_from_slice(&id_bin[..]);