diff options
author | Alex Auvolat <lx@deuxfleurs.fr> | 2025-01-29 19:14:34 +0100 |
---|---|---|
committer | Alex Auvolat <lx@deuxfleurs.fr> | 2025-01-29 19:14:34 +0100 |
commit | 9f3c7c3720d323bc9df3892197e6da5d89d1b84a (patch) | |
tree | 8e1abf81071116f71a3c969a7d5dfcf43d8c1703 /src/api/admin/error.rs | |
parent | a1d081ee840b1727ba1b3f430638a1296738283e (diff) | |
download | garage-9f3c7c3720d323bc9df3892197e6da5d89d1b84a.tar.gz garage-9f3c7c3720d323bc9df3892197e6da5d89d1b84a.zip |
api: better handling of helper errors to distinguish error codes
Diffstat (limited to 'src/api/admin/error.rs')
-rw-r--r-- | src/api/admin/error.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/api/admin/error.rs b/src/api/admin/error.rs index 2668b42d..40d686e3 100644 --- a/src/api/admin/error.rs +++ b/src/api/admin/error.rs @@ -1,3 +1,5 @@ +use std::convert::TryFrom; + use err_derive::Error; use hyper::header::HeaderValue; use hyper::{HeaderMap, StatusCode}; @@ -38,6 +40,19 @@ where } } +/// FIXME: helper errors are transformed into their corresponding variants +/// in the Error struct, but in many case a helper error should be considered +/// an internal error. +impl From<HelperError> for Error { + fn from(err: HelperError) -> Error { + match CommonError::try_from(err) { + Ok(ce) => Self::Common(ce), + Err(HelperError::NoSuchAccessKey(k)) => Self::NoSuchAccessKey(k), + Err(_) => unreachable!(), + } + } +} + impl CommonErrorDerivative for Error {} impl Error { |