diff options
author | Martin Fischer <martin@push-f.com> | 2021-01-19 22:49:09 +0100 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2021-01-19 23:17:45 +0100 |
commit | c55c4a49414f9dbcb637ba5ea765f4af9aebf807 (patch) | |
tree | 691a4a6838a19d5793002f4350c35302561d9152 /src/error.rs | |
parent | e63998de1eb6c348438ecbf6334eb11ec9236bcb (diff) |
request: improve error handling with thiserrorv0.2.1
bump version to 0.2.1
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 |