aboutsummaryrefslogtreecommitdiff
path: root/src/util/error.rs
diff options
context:
space:
mode:
authorAlex <alex@adnab.me>2020-11-08 18:04:52 +0100
committerAlex <alex@adnab.me>2020-11-08 18:04:52 +0100
commit045009da9b7ac4198574bd5aa256c11cfe4ae469 (patch)
treed3014cc2739c5a1bce62ff35efc8417b79ff46ef /src/util/error.rs
parent54166d2a09f488bff080469160d4df6a78db1a3f (diff)
parenta50fa70d45f8b5af68d23d60c3bac2af4ecceb58 (diff)
downloadgarage-045009da9b7ac4198574bd5aa256c11cfe4ae469.tar.gz
garage-045009da9b7ac4198574bd5aa256c11cfe4ae469.zip
Merge pull request 'Refactor error management in API part' (#10) from error-refactoring into master
Reviewed-on: https://git.deuxfleurs.fr/Deuxfleurs/garage/pulls/10
Diffstat (limited to 'src/util/error.rs')
-rw-r--r--src/util/error.rs37
1 files changed, 2 insertions, 35 deletions
diff --git a/src/util/error.rs b/src/util/error.rs
index 0ca1afe7..e5dcf654 100644
--- a/src/util/error.rs
+++ b/src/util/error.rs
@@ -54,9 +54,6 @@ pub enum Error {
#[error(display = "TOML decode error: {}", _0)]
TomlDecode(#[error(source)] toml::de::Error),
- #[error(display = "Timeout: {}", _0)]
- RPCTimeout(#[error(source)] tokio::time::Elapsed),
-
#[error(display = "Tokio join error: {}", _0)]
TokioJoin(#[error(source)] tokio::task::JoinError),
@@ -66,14 +63,8 @@ pub enum Error {
#[error(display = "Remote error: {} (status code {})", _0, _1)]
RemoteError(String, StatusCode),
- #[error(display = "Bad request: {}", _0)]
- BadRequest(String),
-
- #[error(display = "Forbidden: {}", _0)]
- Forbidden(String),
-
- #[error(display = "Not found")]
- NotFound,
+ #[error(display = "Bad RPC: {}", _0)]
+ BadRPC(String),
#[error(display = "Corrupt data: does not match hash {:?}", _0)]
CorruptData(Hash),
@@ -82,18 +73,6 @@ pub enum Error {
Message(String),
}
-impl Error {
- pub fn http_status_code(&self) -> StatusCode {
- match self {
- Error::BadRequest(_) => StatusCode::BAD_REQUEST,
- Error::NotFound => StatusCode::NOT_FOUND,
- Error::Forbidden(_) => StatusCode::FORBIDDEN,
- Error::RPC(_) => StatusCode::SERVICE_UNAVAILABLE,
- _ => StatusCode::INTERNAL_SERVER_ERROR,
- }
- }
-}
-
impl From<sled::TransactionError<Error>> for Error {
fn from(e: sled::TransactionError<Error>) -> Error {
match e {
@@ -114,15 +93,3 @@ impl<T> From<tokio::sync::mpsc::error::SendError<T>> for Error {
Error::Message(format!("MPSC send error"))
}
}
-
-impl From<std::str::Utf8Error> for Error {
- fn from(e: std::str::Utf8Error) -> Error {
- Error::BadRequest(format!("Invalid UTF-8: {}", e))
- }
-}
-
-impl From<roxmltree::Error> for Error {
- fn from(e: roxmltree::Error) -> Error {
- Error::BadRequest(format!("Invalid XML: {}", e))
- }
-}