add macro to render error html template on error from result

master
rascul 2 years ago
parent 9a384c1c2d
commit 7071bd6acc

@ -0,0 +1,20 @@
/// Macro to use error template to return errors
/// must pass it hb then Result
#[macro_export]
macro_rules! render_error {
($hb: expr, $e:expr) => {
match $e {
Ok(r) => r,
Err(e) => {
let data = json!({
"error": e.to_string(),
});
let body = match $hb.render("error", &data) {
Ok(r) => r,
Err(ee) => format!("error: {e}\nerror2: {ee}\n"),
};
return Ok(actix_web::HttpResponse::InternalServerError().body(body));
}
}
};
}

@ -1,4 +1,5 @@
mod client;
mod macros;
mod options;
mod routes;
mod wot_log;

Loading…
Cancel
Save