mirror of
https://git.verdigado.com/NB-Public/simple-wkd.git
synced 2024-10-30 03:05:51 +01:00
Add macro for easier logging
This commit is contained in:
parent
2ce66b9ba0
commit
c67cfc68a2
2 changed files with 26 additions and 0 deletions
|
@ -5,6 +5,31 @@ use thiserror::Error as DeriveError;
|
|||
|
||||
use crate::utils::return_outcome;
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! log_err {
|
||||
($var: expr, $level: ident) => {{
|
||||
let test = $var;
|
||||
if test.is_err() {
|
||||
$level!("{} {}", $crate::settings::ERROR_TEXT, test.as_ref().unwrap_err());
|
||||
test
|
||||
} else {
|
||||
test
|
||||
}
|
||||
}};
|
||||
($var: expr, $level: ident, $panic: expr) => {{
|
||||
let test = $var;
|
||||
if log_err!(test, $level).is_err() {
|
||||
if $panic == true {
|
||||
panic!("{} {}", $crate::settings::ERROR_TEXT, test.unwrap_err());
|
||||
} else {
|
||||
test
|
||||
}
|
||||
} else {
|
||||
$var
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
||||
#[derive(Debug, DeriveError)]
|
||||
pub enum SpecialErrors {
|
||||
#[error("Could not find any primay user email in the keyblock!")]
|
||||
|
|
|
@ -85,6 +85,7 @@ fn get_mailer() -> SmtpTransport {
|
|||
mailer
|
||||
}
|
||||
|
||||
pub const ERROR_TEXT: &str = "An error occoured:";
|
||||
pub const POLICY: &StandardPolicy = &StandardPolicy::new();
|
||||
pub const ROOT_FOLDER: &str = "data";
|
||||
pub static SETTINGS: Lazy<Settings> = Lazy::new(get_settings);
|
||||
|
|
Loading…
Reference in a new issue