From 86e5626f7c140151cb4e181ba43b708e646105a0 Mon Sep 17 00:00:00 2001 From: Franklin Date: Tue, 3 Oct 2023 08:00:59 -0400 Subject: [PATCH] Added macros and err lib to local --- Cargo.lock | 1 - Cargo.toml | 2 +- src/utils/macros.rs | 41 ++++++++++++++++++++++++++++++++++++++++- 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0a992c8..bad8c9c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -519,7 +519,6 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "err" version = "0.1.1" -source = "git+https://git.franklinblanco.dev/franklinblanco/err.git#18cc77b6266d0fc90237a7ccb297d3eeb574f78a" dependencies = [ "serde", "sqlx", diff --git a/Cargo.toml b/Cargo.toml index e2c9eb9..c8e54a2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,4 +15,4 @@ actix-web = "4.1.0" serde_json = { version = "1" } serde = { version = "1.0", features = ["derive"] } log = { version = "0.4", features = ["serde"] } -err = { git = "https://git.franklinblanco.dev/franklinblanco/err.git" } \ No newline at end of file +err = { path = "/Users/franklinblanco/Desktop/Code/rust/libs/dev-deps/err" } \ No newline at end of file diff --git a/src/utils/macros.rs b/src/utils/macros.rs index 2662186..440fe8a 100644 --- a/src/utils/macros.rs +++ b/src/utils/macros.rs @@ -8,7 +8,7 @@ macro_rules! u_res_or_sr { ( $e:expr ) => { match $e { Ok(result) => result, - Err(error) => return Err((500, error.push_trace(actix_web_utils::trace!()))) + Err(error) => return Err((500, error.push_trace(err::trace!()))) } }; ( $e:expr, $status:expr ) => { @@ -53,6 +53,24 @@ macro_rules! u_res_or_res { }; } +/// Macro used to 'unwrap' a result that returns an unknown error type +#[allow(unused_macros)] +#[macro_export] +macro_rules! x_u_res_or_sr { + ( $e:expr, $se:expr ) => { + match $e { + Ok(result) => result, + Err(error) => return Err((400, err::Error::new(err::trace!()).error_type(err::ErrorType::Service($se)))) + } + }; + ( $e:expr, $se:expr, $status:expr ) => { + match $e { + Ok(result) => result, + Err(error) => return Err($status, err::Error::new(err::trace!()).typed(err::error_type(err::ErrorType::Service($se)))) + } + }; +} + #[allow(unused_macros)] #[macro_export] macro_rules! x_e_res_or_db { @@ -64,4 +82,25 @@ macro_rules! x_e_res_or_db { } } }; +} + +#[allow(unused_macros)] +#[macro_export] +macro_rules! x_u_res_db_or_sr { + ( $e:expr ) => { + match $e { + Ok(value) => value, + Err(error) => { + return Err((500, err::Error::new(err::trace!()).error_type(err::ErrorType::Service(err::ServiceError::DatabaseError(error))))) + } + } + }; +} + +#[allow(unused_macros)] +#[macro_export] +macro_rules! service_error { + ( $status:expr, $errtype:expr ) => { + Err(($status, err::Error::new(err::trace!()).error_type(err::ErrorType::Service($errtype)))) + }; } \ No newline at end of file