diff options
author | Alex Auvolat <alex@adnab.me> | 2022-01-05 17:07:36 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2022-01-05 17:07:36 +0100 |
commit | 168a90dfb5489d465d64f066f375e5d06bc1f08c (patch) | |
tree | 7fd1430cb52cf77a654ba93324b40c05d936f5a8 /src/api/error.rs | |
parent | fb1e31add06ee3739fc95099aa5ffe96cf011e9c (diff) | |
download | garage-168a90dfb5489d465d64f066f375e5d06bc1f08c.tar.gz garage-168a90dfb5489d465d64f066f375e5d06bc1f08c.zip |
Fix some error codes
Diffstat (limited to 'src/api/error.rs')
-rw-r--r-- | src/api/error.rs | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/src/api/error.rs b/src/api/error.rs index d6d4a1d7..c19c4f3b 100644 --- a/src/api/error.rs +++ b/src/api/error.rs @@ -35,8 +35,24 @@ pub enum Error { AuthorizationHeaderMalformed(String), /// The object requested don't exists - #[error(display = "Not found")] - NotFound, + #[error(display = "Key not found")] + NoSuchKey, + + /// The bucket requested don't exists + #[error(display = "Bucket not found")] + NoSuchBucket, + + /// The multipart upload requested don't exists + #[error(display = "Upload not found")] + NoSuchUpload, + + /// Tried to create a bucket that already exist + #[error(display = "Bucket already exists")] + BucketAlreadyExists, + + /// Tried to delete a non-empty bucket + #[error(display = "Tried to delete a non-empty bucket")] + BucketNotEmpty, // Category: bad request /// The request contained an invalid UTF-8 sequence in its path or in other parameters @@ -97,7 +113,8 @@ impl Error { /// Get the HTTP status code that best represents the meaning of the error for the client pub fn http_status_code(&self) -> StatusCode { match self { - Error::NotFound => StatusCode::NOT_FOUND, + Error::NoSuchKey | Error::NoSuchBucket | Error::NoSuchUpload => StatusCode::NOT_FOUND, + Error::BucketNotEmpty | Error::BucketAlreadyExists => StatusCode::CONFLICT, Error::Forbidden(_) => StatusCode::FORBIDDEN, Error::InternalError( GarageError::Timeout @@ -115,9 +132,14 @@ impl Error { pub fn aws_code(&self) -> &'static str { match self { - Error::NotFound => "NoSuchKey", + Error::NoSuchKey => "NoSuchKey", + Error::NoSuchBucket => "NoSuchBucket", + Error::NoSuchUpload => "NoSuchUpload", + Error::BucketAlreadyExists => "BucketAlreadyExists", + Error::BucketNotEmpty => "BucketNotEmpty", Error::Forbidden(_) => "AccessDenied", Error::AuthorizationHeaderMalformed(_) => "AuthorizationHeaderMalformed", + Error::NotImplemented(_) => "NotImplemented", Error::InternalError( GarageError::Timeout | GarageError::RemoteError(_) |