mirror of
https://github.com/deuxfleurs-org/garage.git
synced 2026-08-08 13:53:13 +00:00
Error refactoring
This commit is contained in:
@@ -17,9 +17,9 @@ use garage_util::error::Error as GarageError;
|
||||
|
||||
use crate::generic_server::*;
|
||||
|
||||
use crate::admin::error::*;
|
||||
use crate::admin::bucket::*;
|
||||
use crate::admin::cluster::*;
|
||||
use crate::admin::error::*;
|
||||
use crate::admin::key::*;
|
||||
use crate::admin::router::{Authorization, Endpoint};
|
||||
|
||||
|
||||
@@ -16,8 +16,8 @@ use garage_model::garage::Garage;
|
||||
use garage_model::permission::*;
|
||||
use garage_model::s3::object_table::ObjectFilter;
|
||||
|
||||
use crate::admin::key::ApiBucketKeyPerm;
|
||||
use crate::admin::error::*;
|
||||
use crate::admin::key::ApiBucketKeyPerm;
|
||||
use crate::admin::parse_json_body;
|
||||
|
||||
pub async fn handle_list_buckets(garage: &Arc<Garage>) -> Result<Response<Body>, Error> {
|
||||
@@ -98,7 +98,7 @@ pub async fn handle_get_bucket_info(
|
||||
.ok_or_bad_request("Bucket not found")?,
|
||||
_ => {
|
||||
return Err(Error::bad_request(
|
||||
"Either id or globalAlias must be provided (but not both)"
|
||||
"Either id or globalAlias must be provided (but not both)",
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -3,10 +3,10 @@ use hyper::header::HeaderValue;
|
||||
use hyper::{Body, HeaderMap, StatusCode};
|
||||
|
||||
use garage_model::helper::error::Error as HelperError;
|
||||
use garage_util::error::Error as GarageError;
|
||||
|
||||
use crate::generic_server::ApiError;
|
||||
pub use crate::common_error::*;
|
||||
use crate::common_error::CommonError;
|
||||
pub use crate::common_error::{OkOrBadRequest, OkOrInternalError};
|
||||
|
||||
/// Errors of this crate
|
||||
#[derive(Debug, Error)]
|
||||
@@ -47,7 +47,9 @@ pub enum Error {
|
||||
}
|
||||
|
||||
impl<T> From<T> for Error
|
||||
where CommonError: From<T> {
|
||||
where
|
||||
CommonError: From<T>,
|
||||
{
|
||||
fn from(err: T) -> Self {
|
||||
Error::CommonError(CommonError::from(err))
|
||||
}
|
||||
@@ -83,7 +85,10 @@ impl ApiError for Error {
|
||||
}
|
||||
|
||||
fn http_body(&self, garage_region: &str, path: &str) -> Body {
|
||||
Body::from(format!("ERROR: {}\n\ngarage region: {}\npath: {}", self, garage_region, path))
|
||||
Body::from(format!(
|
||||
"ERROR: {}\n\ngarage region: {}\npath: {}",
|
||||
self, garage_region, path
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
pub mod api_server;
|
||||
mod router;
|
||||
mod error;
|
||||
mod router;
|
||||
|
||||
mod bucket;
|
||||
mod cluster;
|
||||
mod key;
|
||||
|
||||
|
||||
use serde::{Deserialize};
|
||||
use hyper::{Request, Body};
|
||||
use hyper::{Body, Request};
|
||||
use serde::Deserialize;
|
||||
|
||||
use error::*;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user