more complete admin API #298

Merged
lx merged 48 commits from admin-api into main 2022-05-24 10:16:40 +00:00
4 changed files with 29 additions and 29 deletions
Showing only changes of commit 926b3c0fad - Show all commits

View file

@ -14,7 +14,7 @@ use crate::helpers::CustomApiErrorBody;
pub enum Error { pub enum Error {
#[error(display = "{}", _0)] #[error(display = "{}", _0)]
/// Error from common error /// Error from common error
CommonError(CommonError), Common(CommonError),
// Category: cannot process // Category: cannot process
/// The API access key does not exist /// The API access key does not exist
@ -34,7 +34,7 @@ where
CommonError: From<T>, CommonError: From<T>,
{ {
fn from(err: T) -> Self { fn from(err: T) -> Self {
Error::CommonError(CommonError::from(err)) Error::Common(CommonError::from(err))
} }
} }
@ -43,12 +43,12 @@ impl CommonErrorDerivative for Error {}
impl From<HelperError> for Error { impl From<HelperError> for Error {
fn from(err: HelperError) -> Self { fn from(err: HelperError) -> Self {
match err { match err {
HelperError::Internal(i) => Self::CommonError(CommonError::InternalError(i)), HelperError::Internal(i) => Self::Common(CommonError::InternalError(i)),
HelperError::BadRequest(b) => Self::CommonError(CommonError::BadRequest(b)), HelperError::BadRequest(b) => Self::Common(CommonError::BadRequest(b)),
HelperError::InvalidBucketName(n) => { HelperError::InvalidBucketName(n) => {
Self::CommonError(CommonError::InvalidBucketName(n)) Self::Common(CommonError::InvalidBucketName(n))
} }
HelperError::NoSuchBucket(n) => Self::CommonError(CommonError::NoSuchBucket(n)), HelperError::NoSuchBucket(n) => Self::Common(CommonError::NoSuchBucket(n)),
HelperError::NoSuchAccessKey(n) => Self::NoSuchAccessKey(n), HelperError::NoSuchAccessKey(n) => Self::NoSuchAccessKey(n),
} }
} }
@ -57,7 +57,7 @@ impl From<HelperError> for Error {
impl Error { impl Error {
fn code(&self) -> &'static str { fn code(&self) -> &'static str {
match self { match self {
Error::CommonError(c) => c.aws_code(), Error::Common(c) => c.aws_code(),
Error::NoSuchAccessKey(_) => "NoSuchAccessKey", Error::NoSuchAccessKey(_) => "NoSuchAccessKey",
Error::KeyAlreadyExists(_) => "KeyAlreadyExists", Error::KeyAlreadyExists(_) => "KeyAlreadyExists",
} }
@ -68,7 +68,7 @@ impl ApiError for Error {
/// Get the HTTP status code that best represents the meaning of the error for the client /// Get the HTTP status code that best represents the meaning of the error for the client
fn http_status_code(&self) -> StatusCode { fn http_status_code(&self) -> StatusCode {
match self { match self {
Error::CommonError(c) => c.http_status_code(), Error::Common(c) => c.http_status_code(),
Error::NoSuchAccessKey(_) => StatusCode::NOT_FOUND, Error::NoSuchAccessKey(_) => StatusCode::NOT_FOUND,
Error::KeyAlreadyExists(_) => StatusCode::CONFLICT, Error::KeyAlreadyExists(_) => StatusCode::CONFLICT,
} }

View file

@ -15,7 +15,7 @@ use crate::signature::error::Error as SignatureError;
pub enum Error { pub enum Error {
#[error(display = "{}", _0)] #[error(display = "{}", _0)]
/// Error from common error /// Error from common error
CommonError(CommonError), Common(CommonError),
// Category: cannot process // Category: cannot process
/// Authorization Header Malformed /// Authorization Header Malformed
@ -48,7 +48,7 @@ where
CommonError: From<T>, CommonError: From<T>,
{ {
fn from(err: T) -> Self { fn from(err: T) -> Self {
Error::CommonError(CommonError::from(err)) Error::Common(CommonError::from(err))
} }
} }
@ -57,13 +57,13 @@ impl CommonErrorDerivative for Error {}
impl From<HelperError> for Error { impl From<HelperError> for Error {
fn from(err: HelperError) -> Self { fn from(err: HelperError) -> Self {
match err { match err {
HelperError::Internal(i) => Self::CommonError(CommonError::InternalError(i)), HelperError::Internal(i) => Self::Common(CommonError::InternalError(i)),
HelperError::BadRequest(b) => Self::CommonError(CommonError::BadRequest(b)), HelperError::BadRequest(b) => Self::Common(CommonError::BadRequest(b)),
HelperError::InvalidBucketName(n) => { HelperError::InvalidBucketName(n) => {
Self::CommonError(CommonError::InvalidBucketName(n)) Self::Common(CommonError::InvalidBucketName(n))
} }
HelperError::NoSuchBucket(n) => Self::CommonError(CommonError::NoSuchBucket(n)), HelperError::NoSuchBucket(n) => Self::Common(CommonError::NoSuchBucket(n)),
e => Self::CommonError(CommonError::BadRequest(format!("{}", e))), e => Self::Common(CommonError::BadRequest(format!("{}", e))),
} }
} }
} }
@ -71,7 +71,7 @@ impl From<HelperError> for Error {
impl From<SignatureError> for Error { impl From<SignatureError> for Error {
fn from(err: SignatureError) -> Self { fn from(err: SignatureError) -> Self {
match err { match err {
SignatureError::CommonError(c) => Self::CommonError(c), SignatureError::Common(c) => Self::Common(c),
SignatureError::AuthorizationHeaderMalformed(c) => { SignatureError::AuthorizationHeaderMalformed(c) => {
Self::AuthorizationHeaderMalformed(c) Self::AuthorizationHeaderMalformed(c)
} }
@ -87,7 +87,7 @@ impl Error {
/// as we are building a custom API /// as we are building a custom API
fn code(&self) -> &'static str { fn code(&self) -> &'static str {
match self { match self {
Error::CommonError(c) => c.aws_code(), Error::Common(c) => c.aws_code(),
Error::NoSuchKey => "NoSuchKey", Error::NoSuchKey => "NoSuchKey",
Error::NotAcceptable(_) => "NotAcceptable", Error::NotAcceptable(_) => "NotAcceptable",
Error::AuthorizationHeaderMalformed(_) => "AuthorizationHeaderMalformed", Error::AuthorizationHeaderMalformed(_) => "AuthorizationHeaderMalformed",
@ -102,7 +102,7 @@ impl ApiError for Error {
/// Get the HTTP status code that best represents the meaning of the error for the client /// Get the HTTP status code that best represents the meaning of the error for the client
fn http_status_code(&self) -> StatusCode { fn http_status_code(&self) -> StatusCode {
match self { match self {
Error::CommonError(c) => c.http_status_code(), Error::Common(c) => c.http_status_code(),
Error::NoSuchKey => StatusCode::NOT_FOUND, Error::NoSuchKey => StatusCode::NOT_FOUND,
Error::NotAcceptable(_) => StatusCode::NOT_ACCEPTABLE, Error::NotAcceptable(_) => StatusCode::NOT_ACCEPTABLE,
Error::AuthorizationHeaderMalformed(_) Error::AuthorizationHeaderMalformed(_)

View file

@ -17,7 +17,7 @@ use crate::signature::error::Error as SignatureError;
pub enum Error { pub enum Error {
#[error(display = "{}", _0)] #[error(display = "{}", _0)]
/// Error from common error /// Error from common error
CommonError(CommonError), Common(CommonError),
// Category: cannot process // Category: cannot process
/// Authorization Header Malformed /// Authorization Header Malformed
@ -80,7 +80,7 @@ where
CommonError: From<T>, CommonError: From<T>,
{ {
fn from(err: T) -> Self { fn from(err: T) -> Self {
Error::CommonError(CommonError::from(err)) Error::Common(CommonError::from(err))
} }
} }
@ -89,12 +89,12 @@ impl CommonErrorDerivative for Error {}
impl From<HelperError> for Error { impl From<HelperError> for Error {
fn from(err: HelperError) -> Self { fn from(err: HelperError) -> Self {
match err { match err {
HelperError::Internal(i) => Self::CommonError(CommonError::InternalError(i)), HelperError::Internal(i) => Self::Common(CommonError::InternalError(i)),
HelperError::BadRequest(b) => Self::CommonError(CommonError::BadRequest(b)), HelperError::BadRequest(b) => Self::Common(CommonError::BadRequest(b)),
HelperError::InvalidBucketName(n) => { HelperError::InvalidBucketName(n) => {
Self::CommonError(CommonError::InvalidBucketName(n)) Self::Common(CommonError::InvalidBucketName(n))
} }
HelperError::NoSuchBucket(n) => Self::CommonError(CommonError::NoSuchBucket(n)), HelperError::NoSuchBucket(n) => Self::Common(CommonError::NoSuchBucket(n)),
e => Self::bad_request(format!("{}", e)), e => Self::bad_request(format!("{}", e)),
} }
} }
@ -115,7 +115,7 @@ impl From<quick_xml::de::DeError> for Error {
impl From<SignatureError> for Error { impl From<SignatureError> for Error {
fn from(err: SignatureError) -> Self { fn from(err: SignatureError) -> Self {
match err { match err {
SignatureError::CommonError(c) => Self::CommonError(c), SignatureError::Common(c) => Self::Common(c),
SignatureError::AuthorizationHeaderMalformed(c) => { SignatureError::AuthorizationHeaderMalformed(c) => {
Self::AuthorizationHeaderMalformed(c) Self::AuthorizationHeaderMalformed(c)
} }
@ -134,7 +134,7 @@ impl From<multer::Error> for Error {
impl Error { impl Error {
pub fn aws_code(&self) -> &'static str { pub fn aws_code(&self) -> &'static str {
match self { match self {
Error::CommonError(c) => c.aws_code(), Error::Common(c) => c.aws_code(),
Error::NoSuchKey => "NoSuchKey", Error::NoSuchKey => "NoSuchKey",
Error::NoSuchUpload => "NoSuchUpload", Error::NoSuchUpload => "NoSuchUpload",
Error::PreconditionFailed => "PreconditionFailed", Error::PreconditionFailed => "PreconditionFailed",
@ -156,7 +156,7 @@ impl ApiError for Error {
/// Get the HTTP status code that best represents the meaning of the error for the client /// Get the HTTP status code that best represents the meaning of the error for the client
fn http_status_code(&self) -> StatusCode { fn http_status_code(&self) -> StatusCode {
match self { match self {
Error::CommonError(c) => c.http_status_code(), Error::Common(c) => c.http_status_code(),
Error::NoSuchKey | Error::NoSuchUpload => StatusCode::NOT_FOUND, Error::NoSuchKey | Error::NoSuchUpload => StatusCode::NOT_FOUND,
Error::PreconditionFailed => StatusCode::PRECONDITION_FAILED, Error::PreconditionFailed => StatusCode::PRECONDITION_FAILED,
Error::InvalidRange(_) => StatusCode::RANGE_NOT_SATISFIABLE, Error::InvalidRange(_) => StatusCode::RANGE_NOT_SATISFIABLE,

View file

@ -8,7 +8,7 @@ pub use crate::common_error::{CommonErrorDerivative, OkOrBadRequest, OkOrInterna
pub enum Error { pub enum Error {
#[error(display = "{}", _0)] #[error(display = "{}", _0)]
/// Error from common error /// Error from common error
CommonError(CommonError), Common(CommonError),
/// Authorization Header Malformed /// Authorization Header Malformed
#[error(display = "Authorization header malformed, expected scope: {}", _0)] #[error(display = "Authorization header malformed, expected scope: {}", _0)]
@ -29,7 +29,7 @@ where
CommonError: From<T>, CommonError: From<T>,
{ {
fn from(err: T) -> Self { fn from(err: T) -> Self {
Error::CommonError(CommonError::from(err)) Error::Common(CommonError::from(err))
} }
} }