diff options
Diffstat (limited to 'src/api/error.rs')
-rw-r--r-- | src/api/error.rs | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/api/error.rs b/src/api/error.rs index ddb021db..a72b7f0f 100644 --- a/src/api/error.rs +++ b/src/api/error.rs @@ -1,5 +1,6 @@ use err_derive::Error; use hyper::StatusCode; +use hyper::{Body, Response}; use garage_util::error::Error as GarageError; @@ -51,6 +52,12 @@ impl Error { _ => StatusCode::BAD_REQUEST, } } + pub fn into_http_response(&self) -> Response<Body> { + let body: Body = Body::from(format!("{}\n", self)); + let mut http_error = Response::new(body); + *http_error.status_mut() = self.http_status_code(); + http_error + } } pub trait OkOrBadRequest { |