diff options
Diffstat (limited to 'src/error.rs')
-rw-r--r-- | src/error.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/error.rs b/src/error.rs index d40ddf3..5f35da2 100644 --- a/src/error.rs +++ b/src/error.rs @@ -3,6 +3,8 @@ use std::fmt::Display; use hyper::StatusCode; /// Encapsulates a status code and an error message. +/// +/// All client errors in [`crate::request`] implement [`Into<Error>`]. #[derive(Debug)] pub struct Error { pub code: StatusCode, @@ -41,4 +43,14 @@ impl Error { pub fn method_not_allowed(message: String) -> Self { Error{code: StatusCode::METHOD_NOT_ALLOWED, message} } +} + +macro_rules! impl_into_http_error { + ($type:ident, $status:expr) => { + impl From<$type> for crate::error::Error { + fn from(err: $type) -> Self { + Self{code: $status, message: format!("{}", err)} + } + } + }; }
\ No newline at end of file |