diff --git a/Cargo.lock b/Cargo.lock index 58a682f..f59a54e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -183,7 +183,7 @@ dependencies = [ [[package]] name = "actix-web-utils" -version = "0.2.9" +version = "0.2.10" dependencies = [ "actix-web", "log", diff --git a/Cargo.toml b/Cargo.toml index 3849d9e..83c0557 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "actix-web-utils" -version = "0.2.9" +version = "0.2.10" edition = "2021" authors = ["Franklin E. Blanco"] description = "Just some useful addons for actix web." diff --git a/src/extensions/generic_error.rs b/src/extensions/generic_error.rs new file mode 100644 index 0000000..f126f35 --- /dev/null +++ b/src/extensions/generic_error.rs @@ -0,0 +1,6 @@ +use std::fmt::Display; + + +pub struct GenericError { + pub error: E +} \ No newline at end of file diff --git a/src/extensions/mod.rs b/src/extensions/mod.rs index e4d56db..49fbeeb 100644 --- a/src/extensions/mod.rs +++ b/src/extensions/mod.rs @@ -1,2 +1,3 @@ pub mod typed_response; -pub mod logger; \ No newline at end of file +pub mod logger; +pub mod generic_error; \ No newline at end of file diff --git a/src/traits/macro_traits.rs b/src/traits/macro_traits.rs index b855bd3..564c41c 100644 --- a/src/traits/macro_traits.rs +++ b/src/traits/macro_traits.rs @@ -1,7 +1,7 @@ use std::fmt::Display; use serde::Serialize; -use crate::{dtos::message::MessageResource, enums::error::Error, extensions::typed_response::TypedHttpResponse}; +use crate::{dtos::message::MessageResource, enums::error::Error, extensions::{typed_response::TypedHttpResponse, generic_error::GenericError}}; /// This trait aims to aid macros defined in this crate so that the macro can take any shape of error and /// do the same thing for all. @@ -32,8 +32,8 @@ impl ReturnableErrorShape for Vec { TypedHttpResponse::return_standard_error_list(status_code, self.to_vec()) } } -impl<'a> ReturnableErrorShape for dyn Display + 'a { +impl ReturnableErrorShape for GenericError{ fn convert_to_returnable(&self, status_code: u16) -> TypedHttpResponse { - TypedHttpResponse::return_standard_error(status_code, MessageResource::new_from_err(self)) + TypedHttpResponse::return_standard_error(status_code, MessageResource::new_from_str(&self.error.to_string())) } }