diff options
author | Alex Auvolat <alex@adnab.me> | 2020-04-09 17:32:28 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2020-04-09 17:32:28 +0200 |
commit | 101444abb3967770ec378ee09f24eb2845dc091d (patch) | |
tree | 7bb838659014b47d220b27d95765174f5d0ae2fe /src/error.rs | |
parent | 4c1aee42d5032066272a051687ac200e874cc13f (diff) | |
download | garage-101444abb3967770ec378ee09f24eb2845dc091d.tar.gz garage-101444abb3967770ec378ee09f24eb2845dc091d.zip |
Some progress
Diffstat (limited to 'src/error.rs')
-rw-r--r-- | src/error.rs | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/error.rs b/src/error.rs index 1481234f..578f73e9 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,5 +1,6 @@ -use err_derive::Error; use std::io; +use err_derive::Error; +use hyper::StatusCode; #[derive(Debug, Error)] pub enum Error { @@ -32,9 +33,22 @@ pub enum Error { #[error(display = "RPC error: {}", _0)] RPCError(String), - #[error(display = "{}", _0)] + #[error(display = "Bad request: {}", _0)] BadRequest(String), + #[error(display = "Not found")] + NotFound, + #[error(display = "{}", _0)] Message(String), } + +impl Error { + pub fn http_status_code(&self) -> StatusCode { + match self { + Error::BadRequest(_) => StatusCode::BAD_REQUEST, + Error::NotFound => StatusCode::NOT_FOUND, + _ => StatusCode::INTERNAL_SERVER_ERROR, + } + } +} |