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));
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
Loading…
Reference in new issue